function createRequestObject(){

	var request_o; //declare the variable to hold the object.

	var browser = navigator.appName; //find the browser name

	if(browser == "Microsoft Internet Explorer"){

		/* Create the object using MSIE's method */

		request_o = new ActiveXObject("Microsoft.XMLHTTP");

	}else{

		/* Create the object using other browser's method */

		request_o = new XMLHttpRequest();

	    }

	return request_o; //return the object

}

var http = createRequestObject(); 

/* Function called to get the product categories list */

function getCountryId(cid,stateid){

	http = createRequestObject(); 

	http.open('get', 'internal_request.php?option=getStateList&cid='+cid+'&stateid='+stateid);

	http.onreadystatechange = handleLoginResults; 

	http.send(null);

}

function handleLoginResults(){

	if(http.readyState == 4){ //Finished loading the response

		var response = http.responseText;

		alert(response);

		document.getElementById('div_show_state').innerHTML = response;

	}

}

//---------------------------------------------

function showCardValue(card_id){

	http = createRequestObject(); 

	http.open('get', 'internal_request.php?action=value_card&card_id='+card_id);

	http.onreadystatechange =function(){

		if(http.readyState == 4){ //Finished loading the response

			var response = http.responseText;

		//	alert(response);

			document.getElementById('div_value_card').innerHTML = response;

			document.getElementById('div_main_value_card').style.display = 'none' ;

			

		}

	}

	http.send(null);

}//function

//----------------------------------
function loadCallingCard(card_id,country_name,connection_fee,minute_cards_value1,minute_cards_value2,page){
	http = createRequestObject();
	http.open('get', 'internal_request.php?action=loadcountry&card_id='+card_id+'&country_name='+country_name+'&connection_fee='+connection_fee+'&minute_cards_value1='+minute_cards_value1+'&minute_cards_value2='+minute_cards_value2+'&page='+page);
	http.onreadystatechange =function(){
		if(http.readyState == 4){ //Finished loading the response
			var response = http.responseText;
			//alert(response);
			document.getElementById('div_load_calling_rate').innerHTML = response;
  		}
	}
	http.send(null);
}//function loadCallingCard
//-----------------------------------------------------------
function populateCardRate(card_id,country_from,country_name,connection_fee,minute_cards_value1,minute_cards_value2,page){
	http = createRequestObject(); 
	http.open('get', 'internal_request.php?action=loadcountry&card_id='+card_id+'&country_from='+country_from+'&country_name='+country_name+'&connection_fee='+connection_fee+'&minute_cards_value1='+minute_cards_value1+'&minute_cards_value2='+minute_cards_value2+'&page='+page);
	http.onreadystatechange =function(){
		if(http.readyState == 4){ //Finished loading the response
			var response = http.responseText;
			document.getElementById('div_load_calling_rate').innerHTML = response;
  		}
	}
	http.send(null);
}//function
//---------------------------------------------
function checkCardAvailabilty(value_price){
	http = createRequestObject(); 
	document.getElementById('div_card_availabilty').style.display ='block';
	document.getElementById('div_card_availabilty').innerHTML ="<img src='images/loading.gif'>";
	http.open('get', 'internal_request.php?action=checkcardavlb&value_price='+value_price);
	http.onreadystatechange =function(){
		if(http.readyState == 4){ //Finished loading the response
			var response = http.responseText;
			if(response  ==  'Yes'){
				document.getElementById('div_card_availabilty').style.display ='block';
				document.getElementById('div_card_availabilty').innerHTML='This card is available.';
			}else{
				document.getElementById('div_card_availabilty').style.display ='block';
				document.getElementById('div_card_availabilty').innerHTML='This card is not available. Please take another															   OR check after some time.we will update soon';
			}
  		}
	}
	http.send(null);
}//function
//---------------------------------------------
function validateForgot(){
		if(document.getElementById("fr_email").value == ""){
				alert('Please Enter Email Address');	
				document.getElementById("fr_email").focus();
				return false;
		}
		if (echeck(document.getElementById("fr_email").value)==false){
			document.getElementById("fr_email").focus();
			return false
		}

}
//------------------------------------------
function validateSignIn(){
		 
		if(document.getElementById("email").value == ""){
				alert('Please Enter Email Address');	
				document.getElementById("email").focus();
				return false;
		}
		if (echeck(document.getElementById("email").value)==false){
			document.getElementById("email").focus();
			return false
		}
		if(document.getElementById("password").value == ""){
				alert('Please Enter Password');	
				document.getElementById("password").focus();
				return false;
		}
}
//------------------------------------------
function ValidateSignUp(){

 		if(document.getElementById("email_address").value == ""){
				alert('Please Enter Email Address');	
				document.getElementById("email_address").focus();
				return false;
		}
		if (echeck(document.getElementById("email_address").value)==false){
			document.getElementById("email_address").focus();
			return false
		}
		if(document.getElementById("pwd").value == ""){
				alert('Please Enter Password');	
				document.getElementById("pwd").focus();
				return false;
		}
		if(document.getElementById("fname").value == ""){
				alert('Please Enter First Name');	
				document.getElementById("fname").focus();
				return false;
		}
		if(document.getElementById("lname").value == ""){
				alert('Please Enter Last Name');	
				document.getElementById("lname").focus();
				return false;
		}
		if(document.getElementById("address1").value == ""){
				alert('Please Enter Address');	
				document.getElementById("address1").focus();
				return false;
		}
		if(document.getElementById("city").value == ""){
				alert('Please Enter City');	
				document.getElementById("city").focus();
				return false;
		}
		if(document.getElementById("zipcode").value == ""){
				alert('Please Enter Zip Code');	
				document.getElementById("zipcode").focus();
				return false;
		}
		if(document.getElementById("country").value == ""){
				alert('Please Select Country');	
				document.getElementById("country").focus();
				return false;
		}
		if(document.getElementById("country_code1").value == ""){
				alert('Please Enter Country Code');	
				document.getElementById("country_code1").focus();
				return false;
		}
		if(document.getElementById("country_code1").value != ""){
			if(isNaN(document.getElementById("country_code1").value)){		
				alert('Code must be number');	
				document.getElementById("country_code1").focus();
				return false;
			}
		}
		if(document.getElementById("city_code1").value == ""){
				alert('Please Enter City Code');	
				document.getElementById("city_code1").focus();
				return false;
		}
		if(document.getElementById("city_code1").value != ""){
			if(isNaN(document.getElementById("city_code1").value)){		
				alert('Code must be number');	
				document.getElementById("city_code1").focus();
				return false;
			}
		}
		if(document.getElementById("ext1").value == ""){
				alert('Please Enter Extension');	
				document.getElementById("ext1").focus();
				return false;
		}
		if(document.getElementById("ext1").value != ""){
			if(isNaN(document.getElementById("ext1").value)){		
				alert('Code must be number');	
				document.getElementById("ext1").focus();
				return false;
			}
		}
  		if(document.getElementById("country_code2").value == ""){
				alert('Please Enter Country Code');	
				document.getElementById("country_code2").focus();
				return false;
		}
		if(document.getElementById("country_code2").value != ""){
			if(isNaN(document.getElementById("country_code2").value)){		
				alert('Code must be number');	
				document.getElementById("country_code2").focus();
				return false;
			}
		}
		if(document.getElementById("city_code2").value == ""){
				alert('Please Enter City Code');	
				document.getElementById("city_code2").focus();
				return false;
		}
		if(document.getElementById("city_code2").value != ""){
			if(isNaN(document.getElementById("city_code2").value)){		
				alert('Code must be number');	
				document.getElementById("city_code2").focus();
				return false;
			}
		}
		if(document.getElementById("ext2").value == ""){
				alert('Please Enter Extension');	
				document.getElementById("ext2").focus();
				return false;
		}
		if(document.getElementById("ext2").value != ""){
			if(isNaN(document.getElementById("ext2").value)){		
				alert('Code must be number');	
				document.getElementById("ext2").focus();
				return false;
			}
		}
		if(document.getElementById("service_type2").value == "Prepaid")	
		{  
			if(document.getElementById("cr_total_amount").value == ""){
				alert('Please Slect Prepaid Card Amount');	
				document.getElementById("cr_total_amount").focus();
				return false;
			}
					
			if(document.getElementById("cr_name").value == ""){
				alert('Please Enter Customer Name');	
				document.getElementById("cr_name").focus();
				return false;
			}
					
			if(document.getElementById("cr_card_type").value == ""){
				alert('Please Select  Card Type');	
				document.getElementById("cr_card_type").focus();
				return false;
			}
	
			if(document.getElementById("cr_ccnumber").value == ""){
				alert('Please Enter Crad Number');	
				document.getElementById("cr_ccnumber").focus();
				return false;
			}
	
			if(document.getElementById("cr_cvv2code").value == ""){
				alert('Please Enter CVV Code ');	
				document.getElementById("cr_cvv2code").focus();
				return false;
			}
	
			if(document.getElementById("cr_expMonth").value == ""){
				alert('Please Select Expiry Month');	
				document.getElementById("cr_expMonth").focus();
				return false;
			}
	
			if(document.getElementById("cr_expYear").value == ""){
				alert('Please Select Expiry Year');	
				document.getElementById("cr_expYear").focus();
				return false;
			}
	 
			if(document.getElementById("cr_address").value == ""){
				alert('Please Enter Street Address');	
				document.getElementById("cr_address").focus();
				return false;
			}
	
	
			if(document.getElementById("cr_zipcode").value == ""){
				alert('Please Enter Postal Code');	
				document.getElementById("cr_zipcode").focus();
				return false;
			}
	
			if(document.getElementById("cr_state").value == ""){
				alert('Please Enter State');	
				document.getElementById("cr_state").focus();
				return false;
			}
	
	
			if(document.getElementById("cr_country").value == ""){
				alert('Please Select Country');	
				document.getElementById("cr_country").focus();
				return false;
			}
	 
	}
		
	if(document.getElementById("chk").checked == false){
			alert('Please click the checkbox to agree the term and condition');	
			return false;
	}
}//function
 
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}

//----------------------
function validateContactUs(){
		
		if(document.getElementById("fname").value  == '' ){
			alert('Please Enter First Name');
			document.getElementById("fname").focus();
			return false;
		}

		
		if(document.getElementById("lname").value  == '' ){
			alert('Please Enter last Name');
			document.getElementById("lname").focus();
			return false;
		}

		
		if(document.getElementById("email").value  == '' ){
			alert('Please Enter Email Address');
			document.getElementById("email").focus();
			return false;
		}

		if (echeck(document.getElementById("email").value)==false){
			document.getElementById("email").focus();
			return false
		}
	
		if(document.getElementById("subject").value  == '' ){
			alert('Please Enter Subject');
			document.getElementById("subject").focus();
			return false;
		}

		
		if(document.getElementById("question").value  == '' ){
			alert('Please Enter Comments');
			document.getElementById("question").focus();
			return false;
		}
}