function createXMLHttp() {

    if (typeof XMLHttpRequest != "undefined") {
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      var aVersions = [ "MSXML2.XMLHttp.5.0",
        "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
        "MSXML2.XMLHttp","Microsoft.XMLHttp"
      ];

      for (var i = 0; i < aVersions.length; i++) {
        try {
            var oXmlHttp = new ActiveXObject(aVersions[i]);
            return oXmlHttp;
        } catch (oError) {
            //Do nothing
        }
      }
    }
    throw new Error("XMLHttp object could be created.");
}

/**
 * updateStateField()
 *
 * This function will update a state select field & state label based off
 * a country select field.  The first 5 parameters are required, the sixth
 * is optional text to be appended to the state label.
 *
 * @param string e				The country select field element ID
 * @param string l				The current language
 * @param string label			The state label ID
 * @param string s				The state select field element ID
 * @param int in_smartway		1 if used in smartway, 0 otherwise
 * @param string add				Additional text to append to the state label
 *
 * Example: updateStateField('create_event_country','name_en','event_state_label','create_event_state',1,':')
 */
function updateStateField(e,l,label,s,in_smartway,add,zipcode)
{
	var xmlhttp = createXMLHttp();
	
	/* Testing */
	var pos = elementPosition(document.getElementById(s+"_container"));
	var nd = document.createElement('div');
	nd.setAttribute('id', 'states_loading_msg');
	nd.className = 'webbox_rollover';
	nd.style.height = '20px';
	nd.style.top = (pos[1] + 20) + 'px';
	nd.style.left = pos[0] + 'px';
	nd.innerHTML = 'Loading states... please wait';
	document.body.appendChild(nd);
	/* Testing End */
	
	var c = document.getElementById(e).value;
	var server = 'ajax_server.php';
	if(in_smartway==0)
	{
		server = 'smartway/' + server;
	}
	xmlhttp.open('GET',server+"?action=state_label&ajax_param_country_id="+c+"&ajax_param_lang="+l,true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4)
		{
			/* Testing */
			document.body.removeChild(document.getElementById('states_loading_msg'));
			/* Testing End */
			response = xmlhttp.responseText;
			var info = response.split("|");
			if(info[1] == 'disabled')
			{
				document.getElementById(s+"_container").innerHTML = '<select name="'+s+'" id="'+s+'"><option value="-">----------</option></select>';
				document.getElementById(s).disabled = true;
				document.getElementById(label).innerHTML = '';
				document.getElementById(label).innerHTML = info[2] + add;
			}
			else
			{
				document.getElementById(s).disabled = false;
				document.getElementById(s+"_container").innerHTML = '<select name="'+s+'" id="'+s+'">'+info[2]+'</select>';
				document.getElementById(label).innerHTML = info[1] + add;
			}
			
			/*if(info[0] == '0')
			{
				document.getElementById(zipcode).disabled = true;
			}
			else
			{
				document.getElementById(zipcode).disabled = false;
			}*/
		}
	}
	xmlhttp.send(null);
}

function openMapWindow(id)
{
	window.open('index.php?page=event_map&event_id='+id,'','width=450,height=450,resizeable=0,toolbar=0');
	return false;
}

function openWindow(url,w,h)
{
	window.open(url,'','width='+w+', height='+h+',resizeable=0, toolbar=0, statusbar=0')
}

function cancelEvent()
{
	document.cancel_event.submit();
	return false;
}

function elementPosition(param){
	var x=0, y=0;
	var obj = (typeof param == "string") ? document.getElementById(param) : param;
	if (obj) {
		x = obj.offsetLeft;
		y = obj.offsetTop;
		var body = document.getElementsByTagName('body')[0];
		while (obj.offsetParent && obj!=body){
			x += obj.offsetParent.offsetLeft;
			y += obj.offsetParent.offsetTop;
			obj = obj.offsetParent;
		}
	}
	coord = new Array(x,y);
	return coord;
}	


function ConfirmMove(url) {
	
doyou = confirm("Are you sure you want to move this Recommendation ? (OK = Yes   Cancel = No)"); //Your question.
	if (doyou == true)
	{
		document.location.href=url;
	}
}
function Cancel(url) {
	
doyou = confirm("Are you sure you want to delete your membership? Canceling your membership will permanently delete your profile and end your monthly billing. (OK = Yes  Cancel = No)"); //Your question.
	if (doyou == true)
	{
		document.location.href=url;
	}
}

// Function defined to set tthe form action for billing
/*function SetAction(billingForm)
{
	var temp=eval(document.billingForm)
	
	for (var i=0; i < document.billingForm.gateway.length; i++)
  	 {
		
	   if (document.billingForm.gateway[i].value=="paypal" && document.billingForm.gateway[i].checked)
		  {
			    document.billingForm.action="index.php";
		  }
	    if (document.billingForm.gateway[i].value=="cc" && document.billingForm.gateway[i].checked)
	      {
				document.billingForm.action="/engine/pages/DoDirectPaymentReceipt.php" ; 	
		  }
   	 }

	
	//if(temp.elements["gateway"][0].checked)
	//{		  
		 //temp.action="index.php";
	//}
	//else
	//{	 
		//temp.action="/engine/pages/DoDirectPaymentReceipt.php" ;
	//}
	document.billingForm.submit();
	
}
function showBillingForm()
{
	divID=document.getElementsByName("ccInfo");
	alert(divID);
	document.divId.style="display:inline";
}
function showMe(id) { // This gets executed when the user clicks on the checkbox
alert("in"+id);
var obj = document.getElementById(id);
if (obj.style.visibility=="hidden") { // if it is checked, make it visible, if not, hide it
obj.style.visibility = "visible";
} else {
obj.style.visibility = "hidden";
}
}*/

//Function to report inappropriate Conetent
function Report(url)
{	
	var temp=window.location;
	window.open ('/report_content.php?url='+temp,'mywindow','width=500,height=275')
}

// function to validate search form in Header section
function chkForm()
{
	if(document.main_search.type.value=="")
	{
		alert("Please sealect a category from the list");
		document.main_search.type.focus();
		return false ;
	}
	else
	{
			return true;
	}
	
}


// New function created to validate payment gateway fields

function checkchar(field,char ,msg)
{
	var str=field.value;
	if(str.indexOf(char)>=0)
	{
		field.focus();
		return ("  -" + msg +"  \n");//Character '"+char+"' Not Allowed in the Field
	}
	return "";
}

function formCheck(formobj){

     if(!checkString(formobj.elements["firstName"],"First Name",false)) return false;  
  	 if(!checkString(formobj.elements["lastName"],"Last Name",false)) return false; 
	 if(!checkString(formobj.elements["creditCardType"],"Credit Card Type",false)) return false;
	 if(!checkString(formobj.elements["creditCardNumber"],"Credit Card Number",false)) return false;
	  if(!checkString(formobj.elements["cvv2Number"],"CVV",false)) return false;
	 if(!checkString(formobj.elements["address1"],"Address",false)) return false;
	 if(!checkString(formobj.elements["city"],"City",false)) return false;
	 if(!checkZIPCode(formobj.elements["zip"],"Zip Code",false)) return false;
	 if(!checkString(formobj.elements["amount"],"Amount",false)) return false;
	 
	/*
	// name of mandatory fields

	var fieldRequired = Array("firstName","lastName","creditCardNumber","address1","city","zip");

	// field description to appear in the dialog box

	var fieldDescription = Array("First Name","Last Name"," Credit Card Number","Address","City","Zip");

	// dialog message

	var alertMsg = "Please complete the following fields:\n";



	var l_Msg = alertMsg.length;    

	for (var i = 0; i < fieldRequired.length; i++){

		var obj = formobj.elements[fieldRequired[i]];

		if (obj){

			switch(obj.type){

			case "select":

				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){

					alertMsg += " - " + fieldDescription[i] + "\n";

				}

				break;

			case "text":

			case "textarea":

				if (obj.value == "" || obj.value == null){

					alertMsg += " - " + fieldDescription[i] + "\n";

				}

				break;

			default:

				if (obj.value == "" || obj.value == null){

					alertMsg += " - " + fieldDescription[i] + "\n";

				}

			}

		}

	}



    
	if (alertMsg.length == l_Msg){

		alertMsg="";
		alertMsg += checkchar(formobj.firstName,",","First Name");
		alertMsg += checkchar(formobj.lastName,",","Last Name");
		alertMsg += checkchar(formobj.creditCardNumber,",","Credit Card Number");
		alertMsg += checkchar(formobj.address1,",","Address");
		alertMsg += checkchar(formobj.city,",","City");
		alertMsg += checkchar(formobj.zip,",","zip");		
		if (alertMsg.length ==0)
			{
				return true;
			}
		else
			{				
				alert(alertMsg);
				return false;
			}

	}else{

		alert(alertMsg);

		return false;

	}
*/
}
function clearSearchBox()
{
  document.main_search.keywords.value="";
}
function checkEmailForm()
{
		if(!checkString(nm_email.elements["FName"],"First Name",false)) return false;  
  		if(!checkString(nm_email.elements["Email"],"Email",false)) return false;  
		
   		if(document.nm_email.t_c.checked)
		{
			return true;
		}
		else
		{
				alert("Please accept the User Agreement");
				document.nm_email.t_c.focus();
				return false;
		}
}
function ChkAgreement()
{
	if(document.register.t_c.checked)
		{
			return true;
		}
		else
		{
				alert("Please accept the User Agreement");
				document.register.t_c.focus();
				return false;
		}
	
}

//  End -->







