// ***********  JavaScript 		  ***********************
// ***********  Some of my own... ***********************

// Global Params
var pars = "";
var PenNameChecked=0;
var EmailAddressChecked=0;
var EmailAddressValid=1;
var HasReadTermsAndPrivacyChecked=0;
var PasswordChecked=0;
//***********************************


function waitMyCursor() {
	document.body.style.cursor = "wait";
	setTimeout("clearMyCursor()",2500);
}

function clearMyCursor() {
	document.body.style.cursor = "default";
}


function pointerMyCursor(objID) {
	$(objID).style.cursor='pointer';
}

function defaultMyCursor(objID) {
	$(objID).style.cursor='default';
}

insertCodeFragment= function(ContainerToUpdate,theFileVars) {
	//waitMyCursor();
	new Ajax.Updater(ContainerToUpdate,theFileVars, {asynchronous:true});return false;
};

iCF2=function(divToUpdate,theFileVars){
	new Ajax.Updater (divToUpdate, theFileVars, {
			asynchronous: true
			,evalScripts: true
		});
	return false;
};

iCF3=function (divToUpdate,theFileVars,placeWhere) {
	switch(String(placeWhere)){
	
	case 'After':
	new Ajax.Updater (divToUpdate, theFileVars, {
			asynchronous: true
			,evalScripts: true
			,insertion: Insertion.After 
		});
	return false;
	break
	
	case 'Before':
	new Ajax.Updater (divToUpdate, theFileVars, {
			asynchronous: true
			,evalScripts: true
			,insertion: Insertion.Before 
		});
	return false;
	break
	
	case 'Bottom':
	new Ajax.Updater (divToUpdate, theFileVars, {
			asynchronous: true
			,evalScripts: true
			,insertion: Insertion.Bottom 
		});
	return false;
	break
	
	case 'Top':
	new Ajax.Updater (divToUpdate, theFileVars, {
			asynchronous: true
			,evalScripts: true
			,insertion: Insertion.Top 
		});
	return false;
	break
	
	default:
	new Ajax.Updater (divToUpdate, theFileVars, {
			asynchronous: true
			,evalScripts: true
		});
	return false;
	}// end of switch

};


// *************   Visibility / Display functions ******************************


function toggleVisibility_II(me){
		if ($(me).style.visibility=="hidden"){
			$(me).style.visibility="visible";
			}
		else {
			$(me).style.visibility="hidden";
			}
		}

function toggleDisplay_II(me){
		if ($(me).style.display=="none"){
			$(me).style.display="block";
			}
		else {
			$(me).style.display="none";
			}
		}


function toggleDiv( element ) {
    var e = $(element);
    if (e) {
        e.style.display = ((e.style.display != 'block') ? 'block' : 'none');
    }
}

function toggleDivON( element ) {
    var e = $(element);

    if (e) {
        e.style.display = ((e.style.display != 'block') ? 'block' : 'block');
    }
}

function toggleDivOFF( element ) {
    var e = $(element);

    if (e) {
        e.style.display = ((e.style.display != 'block') ? 'block' : 'none');
    }
}

// ************  END Visibility / Display functions ******************************

/***************************************************/


var clearFieldValue = '';
var clearFieldDefaultValue = '';
clearField=function(FieldName,dValue) {
	clearFieldValue = $(FieldName).value;
	if (String(clearFieldValue)==String(dValue)) $(FieldName).value='';	
};
PasteInFields=function(FieldName,checkValue,GroupNum) {
 	if ($(FieldName).value=='') {
 	$(FieldName).value=clearFieldValue;
	}
	
	clearFieldValue = '';
};


/********************************************/
// JavaScript Document


inviteFriends=function(daForm){
	alert("I was lost but now I am found.");
};


processForm_v1=function(daForm){
	var pars = $(daForm).serialize() ;
	var r=confirm(pars);
		if (r==true)
		  {
		 // alert("You pressed OK!");
				var url = 'inc/forms_Processing_v1.asp';
				var myAjax = new Ajax.Request(
					url, 
					{
						 method: 'post' 
						,parameters: pars
						,onSuccess: function(transport){
							 var response = transport.responseText || "no response text";
							 //if (response=='Done Right') alert('Response Text evalueated');
							 //alert("Success! \n\n" + response);
						}
						,onFailure: function(transport){ 
							var response = transport.responseText || "no response text";
							alert('Something went wrong...\n\n' + response) 
						}
			
			
				});	 
			}
		else
		  {
		  alert("You pressed Cancel!");
		  }

};

processForm_v1_Display=function(daForm) {
	
	var pars = $(daForm).serialize() ;
		var r=confirm(pars);
		if (r==true)
		  {
			iCF3('DisplayDiv','inc/forms_Processing_v1.asp?'+pars,'') ;
	      }
		else
		  {
		  alert("You pressed Cancel!");
		  }


};


processForm_RequestRankingReport=function(daForm){
	//pars = $(daForm).serialize(true) ;
	pars = "FormFunction="+$('Form_id').value+"&Contact="+$('Contact').value+"&Company="+$('Company').value+"&WebAddress="+$('WebAddress').value+"&Phone="+$('Phone').value+"&Email="+$('Email').value+"&Locate="+$('Locate').value+"&WhatAboutYou_ids="+$('WhatAboutYou_ids').value+"&Internet_Marketing_Service_1="+$('Internet_Marketing_Service_1').value+"&Internet_Marketing_Service_2="+$('Internet_Marketing_Service_1').value+"&Internet_Marketing_Service_3="+$('Internet_Marketing_Service_1').value+"&Internet_Marketing_Service_4="+$('Internet_Marketing_Service_1').value+"&Internet_Marketing_Service_5="+$('Internet_Marketing_Service_1').value+"&Internet_Marketing_Service_6="+$('Internet_Marketing_Service_1').value+"&Comment="+$('Comment').value;

	processForm_v2();
	 pars = "";
};

var	ContactCheck, 	CompanyCheck,	WebAddressCheck,	PhoneCheck,	EmailCheck = 0;

checkGroupNum=function(GroupNum){
	var returnValue = 0;
	switch(String(GroupNum)){
	
	case 'Group_6':
	 if (ContactCheck+CompanyCheck+WebAddressCheck+PhoneCheck+EmailCheck==4){ returnValue = 1; }
	
	break
	
	default:
	}// end of switch
	
	return returnValue;
	
};

allowFormSubmit=function(el,GroupNum){
	var createGroupNum='Group_'+GroupNum;
	var e = $(el);
	if (checkGroupNum(createGroupNum)) {
	//alert("inside 3");
	    if (e) {
        $(el).disabled = false; 
    	}
	//toggleDisabledList( el );
	} else { 
		if (e) {
		$(el).disabled = true; 
		}
	}

};

processForm_v2=function(daForm){
	var url = 'forms_Processing_v1.asp';
	var myAjax = new Ajax.Request( 
	url, 
		{
			 method: 'post' 
			,parameters: pars
			,onSuccess: function(transport){
				 var response = transport.responseText || '{ "FormFunction":"No Response", "SuccessRank":0,"trackSuccess":"Bad Form" }';
				//alert('onSuccess returned: '+response);
				 nextMove(response);
			}
			,onFailure: function(transport){ alert('Something went wrong...\n\n'+transport.responseText) ;}


	});	

};

nextMove = function (data_) {	
	var data = data_.evalJSON(true);
	switch(String(data.FormFunction)) { 
		
		case "RequestFreeRankingReport":
			if (data.SuccessRank==1&&data.SuccessRank==1) {
				alert("Email has been sent.\nWe will respond ASAP.\n\n  Thank you!");
				iCF3('RightColumn_div','blank_1.asp','');
			} else {
				alert("Email failed,  Sorry about that.");
				
			}
		  //execute code block 2
		  break;
		  
		  default:
		  alert("nextMove ended in default");
	
	} // End Switch

	
};

