function isEmail(Mail) {
Mail=Mail.toLowerCase();
return (Mail.search(/^[a-zA-Z]+([_\.-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([\.-]?[a-zA-Z0-9]+)*(\.[a-zA-Z]{2,4})+$/) != -1);
}

function displayhtml(yn){
	switch(yn){
	case 'y':
		document.getElementById("CCCdiv").style.display = "block";
	break;
	case 'n':
		document.getElementById("CCCdiv").style.display = "none";
	break;
	}
}
function trim(stringx) {
	return stringx.replace(/^\s*/, "").replace(/\s*$/, "");
}


function SaveLoadDisp(OnOff){
		switch(OnOff){
		case 'on':
      document.getElementById('API_AddLead').style.display = "none";
			document.getElementById('API_AddLead').style.visibility = "hidden";
			document.getElementById('saveDisplay').style.backgroundImage='url("rotator_25px.gif")';
			document.getElementById('saveDisplay').style.backgroundRepeat="no-repeat";
			document.getElementById('saveDisplay').style.zIndex = "11000";
			document.getElementById('saveDisplay').style.display = "block";
			document.getElementById('saveDisplay').style.visibility = "visible";
		break;
		case 'off':
			document.getElementById('saveDisplay').style.backgroundImage='';
			document.getElementById('saveDisplay').style.zIndex = "-1";
			document.getElementById('saveDisplay').style.display = "none";
			document.getElementById('saveDisplay').style.visibility = "hidden";
			document.getElementById('API_AddLead').style.display = "block";
			document.getElementById('API_AddLead').style.visibility = "visible";
		break;
		}
	}

function display(){
	var iframe = document.getElementById("cnfm");
	if(iframe.contentWindow.document.body.innerHTML != ""){
		//alert(iframe.contentWindow.document.body.innerHTML );
		stringx = iframe.contentWindow.document.body.innerHTML;
		stringx = stringx.toUpperCase();
		//stringx = stringx.split("<BR>");
			//strip = stringx[0].split("=");
			alert(stringx);
				switch(stringx){
				case 'SUCCESS':
						document.getElementById("CCCdiv").innerHTML = "Thank You <br>Your Information Has Been Submitted. <br>We will be contacting you shortly";
						SaveLoadDisp('off');
				break;
				case 'FAILURE':
				    alert("There was a error please try again");
						displayhtml('y');
						SaveLoadDisp('off');
				break;
				default:
						alert("There was a error please try again");
						displayhtml('y');
						SaveLoadDisp('off');
				}
				
	}
}

function valicheck(){
	var allTags = document.body.getElementsByTagName('*');
	var ids = [];
	for (var tg = 0; tg< allTags.length; tg++) {
	    var tag = allTags[tg];
	    if (tag.id) {
		    ids.push(tag.id);
	     }   
	}
	for(i=0;i<ids.length;i++){
		vals = document.getElementById(ids[i]).value;
		switch(ids[i]){
		case 'API_AddLead':
		case '__VIEWSTATE':
		case 'address1':
		case 'address2':
		case 'city':
		case 'state':
		case 'zip':
		case 'workphone':
		case 'homephonetime':
		case 'debtamount':
		case 'billstatus':
		case 'cnfm':
		case 'submit':
		case 'Reset':
		case 'advertisingid':
		break;
		case 'email':
			emval = isEmail(vals);
			if(!emval){
				alert("Email format is incorect");
				return false;
			}
		break;
		default:
			if(vals == ""){
				alert("Make sure all required fields are filled in");
				return false;
			}
		}
	}
	return true;
}
function numonly(name){
	validate = document.getElementById(name);
	validate.value = validate.value.replace(/[^0-9\.]/g, "");
}
function valichecksmall(){
	theForm = document.API_AddLead;

	for(i=0; i<theForm.length; i++){
		vals = theForm[i].value;
		switch(theForm[i].name){
			case 'API_AddLead':
			case '__VIEWSTATE':
			case 'cnfm':
			case 'subyn':
			case 'submit':
			case 'advertisingid':
				break;
			
			case 'email':
				emval = isEmail(vals);
				if(!emval){
					alert("Email format is incorect");
					return false;
				}
			
				break;
			default:
				if(vals == ""){
					alert("Make sure all required fields are filled in");
					return false;
				}
		}
	}
	return true;
}
/*function valichecksmall(){
	var allTags = document.body.getElementsByTagName('*');
	var ids = [];
	for (var tg = 0; tg< allTags.length; tg++) {
	    var tag = allTags[tg];
	    if (tag.id) {
		    ids.push(tag.id);
	     }   
	}
	for(i=0;i<ids.length;i++){
		vals = document.getElementById(ids[i]).value;
		switch(ids[i]){
		case 'API_AddLead':
		case '__VIEWSTATE':
		case 'cnfm':
		case 'subyn':
		case 'submit':
		case 'advertisingid':
		break;
		case 'email':
			emval = isEmail(vals);
			if(!emval){
				alert("Email format is incorect");
				return false;
			}
		break;
		default:
			if(vals == ""){
				alert("Make sure all required fields are filled in");
				return false;
			}
		}
	}
	return true;
}*/
function loadframe(curlit){
						SaveLoadDisp('on');
    					
    				//stringx = "<?php echo $rez; ?>";
						//alert(curlit);
       			switch(curlit){
    				case 'SUCCESS':
    						document.getElementById("CCCdiv").innerHTML = "Thank You <br>Your Information Has Been Submitted. <br>We will be contacting you shortly";
    				break;
    				case 'FAILURE':
    				    alert("There was a error please try again");
    						displayhtml('y');
    				break;
    				default:
    						alert("There was a error please try again");
    						displayhtml('y');
    				}
    				SaveLoadDisp('off');
					//urlqry = "<?php echo $urlquery;?>";
					//document.getElementById("cnfm").src = "mockform.php?"+urlqry;
					
					//displayhtml('n');
}
