//
// JavaScript Form Tricks
// Mike Jones
// StyleDig



//used to advance form fields automatically
function advance(currentID, nextID, charLimit) 
{
	var current=window.document.getElementById(currentID);
	var next=window.document.getElementById(nextID);
	
    if (current.value.length == charLimit)
		next.focus();
       // window.document.formname[nextField].focus();
}

//submit search result filter form
function SubmitSortieForm(base_url)
{
	var sortie=window.document.getElementById('sortie');
	
	var action = base_url + "filter/" + sortie.value;
	forward_url(action);
}
	
//What happens when you click on a grey pre-filled in input box
function ActivateGreyBox(id, def)
{
	var box = window.document.getElementById(id);
	if(box.value == def || def == "")
	{
		box.style.backgroundColor = '#FFFFFF';
		box.style.color = '#000000';
		box.value = "";
	}
}

// show or hide an element box */
function showHide(elem)
{
	var box = document.getElementById(elem);
	if (box.style.display != 'block')
	{
		$(box).slideDown(700);
    	//document.getElementById(elem).style.display = 'block';
	}
	else
	{
		$(box).slideUp(700);
    	//document.getElementById(elem).style.display = 'none';
	}
}

// show or hide an element box */
function showReviewBox(elem)
{
    document.getElementById(elem).style.display = 'block';
}

//Add a dynamic size or shipping div box for the add item page
function addDynamicBox(delLinkSearchString)  //search string that specifies the location to put the delete link
{				
	var addbox = document.getElementById('dynamicbox');
	var addbox_container=document.getElementById('dynbox_container');

	var newBox=document.createElement('div');
	
	//keep naming system in order so the delete button refers to the right element
	var clase = "dynamicBoxClass";
	
	//we use the time to create a unique classname for this element
	var d = new Date();
	newBox.className = "dynamicBoxClass_" + d.getTime();
	
	//copy inner html from first box
	var content = addbox.innerHTML;
	
	//add delete link
	var dellink = '<div class="remove_ship_button" onclick="deleteDynamicBox(\'' + newBox.className + '\')">[remove]</div>';
	if(content.search(delLinkSearchString)>0)
		content = content.replace(delLinkSearchString, delLinkSearchString + dellink);
	else if (content.search(delLinkSearchString.toUpperCase())>0)
		content = content.replace(delLinkSearchString.toUpperCase(), delLinkSearchString + dellink); //for IE which converts DIV's to uppercase IDK why
	newBox.innerHTML = content;
	addbox_container.appendChild(newBox);  
}

//delete a dynamic box
function deleteDynamicBox(classname)
{							
	var deleteBox = getElementsByClass(classname);
	deleteBox[0].innerHTML="";
}


//Check username availability
function check_name_callback(data)
{
	var divBox = window.document.getElementById('msgbox');
	divBox.innerHTML = data;
}
function check_username_avail()
{
	var UserName = window.document.getElementById('username');
	var temp = $.post("../callbacks/checkusername.php", { username: UserName.value}, check_name_callback, "html");
	//alert(temp);
}

//replace str with all "val" characters (used in login form to replace password)
function string_replace(str, val)
{
    for(var i=0;i<str.Len;i++)
        str[i]=val;
    return str;
}



