<!--
lastcategory = 0;

function ShowProductList(ID){
	
	if(ID == 5)
		top.location.href = 'http://findagenerator.com';
	
	if(lastcategory > 0){
		document.getElementById("category"+lastcategory).style.backgroundColor = '#FFFFFF';
		document.getElementById("category"+lastcategory).style.color = '#333333';
		document.getElementById("category_text"+lastcategory).style.color = '#333333';
	}
	document.getElementById("category"+ID).style.backgroundColor = '#336600';
	document.getElementById("category"+ID).style.color = '#333333';
	document.getElementById("category_text"+ID).style.color = '#333333';
	document.getElementById("products").innerHTML = document.getElementById("productList"+ID).innerHTML;
	lastcategory = ID;
}
//-->


//form checking
function SendForm(){
	ShowBlock("PleaseWait");
}

function ConfirmDelete(to)
{
		var Agree = confirm('Are you sure you want to delete ' + CurrentItemTitle);
    if (Agree) {
		window.location.href = to + CurrentItemID;
		return true ;
    } else
    	return false ;
}

function GetHTTPRequest(call, onreadystatechange) {
	call = window.location.protocol+"//"+window.location.host+call;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		try {
			req.onreadystatechange = onreadystatechange;
     		req.open("GET", call , true);     	
			req.send(null);
   		} catch (e) {
   	  		alert(e);
   		}
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = onreadystatechange;
			req.open("GET", call, true);
			req.send();
		}
	}
}

function PostHTTPRequest(script, call, onreadystatechange) {
	script = window.location.protocol+"//"+window.location.host+"/"+script;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		try {
			req.onreadystatechange = onreadystatechange;
			req.open("POST", script, true);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			req.send(call);
		} catch (e) {
   	  		alert(e);
   		}
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = onreadystatechange;
			req.open("POST", script, true);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			req.send(call);
		}
	}
}

function ahref(to) {

	 var to = to;
	 window.location.href = to;

}

function popuplink(status,height,width,url) 
{
    if(status == 1 && popup == null) 
    { 
		    var popup = open(url, "", "width=" + width + ",height=" + height + ",screenX=0,screenY=0,top=0,left=10,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
    		popup_window = popup; 
		}
    
    if (status == 1 && popup != null)
    { 
			  popup.focus(); 
		}
    
    if (status == 0) 
    { 
		    popup_window.close(); 
		}
}

function ShowFooter(){
	document.getElementById("ClientProfile").style.display = "none";
	document.getElementById("Footer").style.display = "block";
	document.getElementById("EditFooter").focus();
}

function inspect(elm)
{
	var str = "";
	for (var i in elm)
	{
		if(elm.getAttribute(i))
			str += i + ": " + elm.getAttribute(i) + ", ";
	}
	alert(str);
};

function ShowBlock( Obj ){
	document.getElementById(Obj).style.display = "block";
}
function ShowInline( Obj ){
	document.getElementById(Obj).style.display = "inline";
}
function Hide( Obj ){
	document.getElementById(Obj).style.display = "none";
}
function Disable( Obj ) {
	document.getElementById(Obj).disabled = true;
}
function Enable( Obj ) {
	document.getElementById(Obj).disabled = false;
}
// Get element by ID
function GEBI( Obj ){
	return document.getElementById(Obj);
}
function FindElementByClass( Node, NodeType, ClassName ) {
	var Items = Node.getElementsByTagName( NodeType );
	for( var x = 0; x < Items.length; x++ ) {
		if( Items.item( x ).className == ClassName )
			return Items.item( x );
	}
	return null;
}
// Get 'value' of span with class name
function GetSpanValue( Node, ClassName ) {
	try {
		return FindElementByClass( Node, "span", ClassName  ).firstChild.nodeValue;
	} catch(e) {
		return "";
	}
}
function SetSpanValue( Node, ClassName, Value ) {
	try {
		return FindElementByClass( Node, "span", ClassName  ).firstChild.nodeValue = Value;
	} catch(e) {
		return FindElementByClass( Node, "span", ClassName  ).innerHTML = Value;
	}
}
function SetTextFieldWithSpan( Field, Node, ClassName) {
	GEBI( Field ).value = GetSpanValue( Node, ClassName );
}
function SetListbox( Listbox, Value ) {
	var Options = GEBI( Listbox ).getElementsByTagName("option");
	for(var x = 0; x < Options.length; x++)
		if(Options.item(x).value == Value) {
			Options.item(x).selected = true;
			return true;
		}
	return false;
}
function SetListboxWithSpan( Listbox, Node, ClassName ) {
	SetListbox( Listbox, GetSpanValue( Node, ClassName ) );
}
function SetCheckbox( Checkbox, Value ) {
	if( Value == "Y" || Value == "1" || Value == true )
		GEBI( Checkbox ).checked = true;
	else
		GEBI( Checkbox ).checked = false;
}
function SetCheckboxWithSpan( Checkbox, Node, ClassName ) {
	SetCheckbox( Checkbox, GetSpanValue( Node, ClassName ) );
}

function ValidateForm(){
	if(CheckForm('form1')){
		if(GEBI('recaptcha_response_field').value > ''){
			PostHTTPRequest("/http_requests/recaptcha.php", "recaptcha_challenge_field="+ GEBI('recaptcha_challenge_field').value + '&recaptcha_response_field=' + GEBI('recaptcha_response_field').value, ValidateForm_ProcessStateChange);	
		} else {
			alert("Please enter the two words to submit this request");
		}
	} else {
		alert("Please fill out all required information at the top of the form.");
	}	
}

function ValidateForm_ProcessStateChange(){
	if (req.readyState == 4) {
    	if (req.status == 200) {
			if(req.responseText == '1'){
				document.forms[0].submit();
			} else {
				alert("The words you entered did not match. Please enter the two words to submit this request");
			}
		}	
	}
}

function CheckForm(FormName,SectID){
	
	var ValidationFlag = true;
	
	for(var i = 0; i < document.forms[FormName].elements.length; i++){
		if(GEBI(document.forms[FormName].elements[i].name+"RequiredForm"+SectID)){
			if(document.forms[FormName].elements[i].value == '' || document.forms[FormName].elements[i].value == ' '){
				GEBI(document.forms[FormName].elements[i].name+"RequiredForm"+SectID).innerHTML = "(required)";
				ShowBlock(document.forms[FormName].elements[i].name+"RequiredForm"+SectID);
				ValidationFlag = false;
			} else {
				GEBI(document.forms[FormName].elements[i].name+"RequiredForm"+SectID).innerHTML = "*";
			}	
		}
	}
	
	return ValidationFlag;
}


///////////////NEW FORM FUNCTIONS///////////////////
function saveSection(SectNum, CurrSect, NextSect){
	
	if(CheckForm('form1',SectNum)){
		var params = '';
	
		if(GEBI("saved_form_id").value > 0){
			params = "saved_form="+GEBI("saved_form_id").value+"&section="+ SectNum;
		} else {
			params = "form="+ GEBI("form_id").value +"&section="+ SectNum;	
		}
	
		elements = GEBI('sect_'+ SectNum +'_element_ids').value.split(',');
		for(var i = 0; i < elements.length; i++){
			if(GEBI(elements[i])){
				if((GEBI(elements[i]).type == "checkbox" && GEBI(elements[i]).checked) || GEBI(elements[i]).type != "checkbox"){
					params += "&"+elements[i]+"="+GEBI(elements[i]).value;
				} else if(GEBI(elements[i]).type == "checkbox" && !GEBI(elements[i]).checked){
					params += "&"+elements[i]+"=";	
				}
			}
		}
		
		PostHTTPRequest("/http_requests/save_form.php", params, saveSection_ProcessStateChange);
		
		if(NextSect){
			ShowBlock("form-section"+NextSect);
			Hide("form-section"+CurrSect);
		}
	}
}

function saveSection_ProcessStateChange(){
	if (req.readyState == 4) {
    	if (req.status == 200) {
			//alert(req.responseText);
			if(req.responseText > 0){
				GEBI("saved_form_id").value = req.responseText;
				GEBI("sf_id").value = req.responseText;
				//alert("Section Saved");
			} else {
				alert("Section was not saved. Please go back and try again. DO NOT USE THE BROWSER'S BANCK BUTTON. Use the button provided at the bottom of this page or you may lose your data.");	
			}
		}	
	}
}

function previousSection(CurrSect, PrevSect){
	ShowBlock("form-section"+PrevSect);
	Hide("form-section"+CurrSect);
}

function ShowSectionGroup(GrouID){
	ShowBlock("form-section-group"+GrouID);
}

function HideSectionGroup(GrouID){
	Hide("form-section-group"+GrouID);
}

//Form processing functions
function ProcessUpload(){
	ValidationFlag = false;
	Ext = GEBI("doc").value.split('.');
	AllowableExt = GEBI("doc_file_extensions").value.split(',');
	ExtFlag = false;
	for(var j = 0; j < AllowableExt.length; j++){
		if(Ext[Ext.length - 1] == AllowableExt[j]){
			ExtFlag = true;
		}
	}
	if(ExtFlag){
		GEBI("docRequired").innerHTML = "";
		ValidationFlag = true;
	} else {
		GEBI("docRequired").innerHTML = "(<strong>"+Ext[1]+"</strong> is not an accepted file extenstion. Please use one of the following: "+GEBI("doc_file_extensions").value+")";
	}

	if(ValidationFlag){
		
		Hide("FileUploadBtns");
		ShowBlock("UploadMessage");

		return true;
	}
	return false;
}

function ShowDocPreview(DocID){
	
	parent.document.getElementById("docUploader").style.display = "none";
	parent.document.getElementById("UploadMessage").style.display = "none";
	parent.document.getElementById("FileUploadBtns").style.display = "block";

	if(parent.frames["iframeSource"].document.getElementById("iframeResult").innerHTML == "error"){
		alert("Document failed to upload. Please try again.");
	} else {
		tmp = parent.frames["iframeSource"].document.getElementById("iframeResult").innerHTML.split('|');
		parent.document.getElementById(DocID+"Preview").innerHTML = tmp[1];
		parent.document.getElementById(DocID).value = tmp[0];
		parent.document.getElementById(DocID).style.display = "none";
		parent.document.getElementById("RemoveDoc"+DocID).innerHTML = "<a href=\"#\" onclick=\"RemoveDoc('"+DocID+"'); return false;\">remove</a>";
	}
	
}

function RemoveDoc(DocID){
	GEBI(DocID).value = 'Attach File';
	GEBI(DocID).style.display = "inline";
	GEBI(DocID+"Preview").innerHTML = '';
	GEBI("RemoveDoc"+DocID).innerHTML = "";
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

