﻿//------------------------------------------------------------------------------------------------------------------------------------------------
//ONLOAD - Event:
if (window.onload){
	var funPublicLoad = window.onload;
	window.onload = new Function("funPublicLoad(); jsPublic_OnLoad();");
}
else
	window.onload = Public_OnLoad;
	
//------------------------------------------------------------------------------------------------------------------------------------------------	
var _loginButtonOver;
var _loginButtonOut;
var _offerOut;
var _offerOver;
var _orderNowButtonOut;
var _orderNowButtonOver;
var _orderNowButtonDown;

//------------------------------------------------------------------------------------------------------------------------------------------------
function Public_OnLoad(){	

	//Preload images:
	_loginButtonOver = new Image();
	_loginButtonOver.src = "images/siteskin/login_over.gif";
	_loginButtonOut = new Image();
	_loginButtonOut.src = "images/siteskin/login_out.gif";		
	
	_offerOver = new Image();
	_offerOver.src = "images/siteskin/99anystate_mouseover.png";
	_offerOut = new Image();
	_offerOut.src = "images/siteskin/99anystate_regular.png";	
	
	_orderNowButtonOver = new Image();
	_orderNowButtonOver.src = "images/siteskin/OrderButton_mouseover.png";
	_orderNowButtonOut = new Image();
	_orderNowButtonOut.src = "images/siteskin/OrderButton_regular.png";			
	
	_orderNowButtonDown = new Image();
	_orderNowButtonDown.src = "images/siteskin/OrderButton_click.png";
	
}

//----------------------------------------------------------------------------------------------------------------------------------------
function LoadContactForm(toEmail, subject, version){   
	
	var page = "contact.aspx?qsToEmail=" + toEmail + "&qsSubject=" + escape(subject) + "&qsVersion=" + escape(version);

	document.location.href = page;

}

function GoToOrderForm(orderType){

 
    //First, get the current webserverpath:

    var webServerPath = document.frmMain.hidWebServerPath.value; //Note hidWebServerPath should be added to your page just under your page's 

                                                                     //opening form tag, make sure it has runat="server", then in your codefile

                                                                     //add the following line in the Page_Load routine:

                                                                     //

                                                                     //Me.hidWebServerPath.value = Session("sWebServerPath")

                                                                     

                                                                     //That line of code will populate the relative web server path into the

                                                                     //hidden field which in turn will be picked up by this function when

                                                                     //called from the client.

    

    //Then build a secure url and pass the order type as a querystring in the URL, the order.aspx codebehind will pick this querystring up

    //and instantiate the matching UOF order form control:	
    var url = "https:" + webServerPath + "order.aspx?qsOrderType=" + orderType;

    
    //Send the user to the order form:

    document.location.href = url;     

}

//------------------------------------------------------------------------------------------------------------------------------------------------
function LoginToAffiliateAccount(ready, windowName){ 

    var form = document.frmMain;
	
	//Check to make sure required fields are filled in:
	if (Trim(form.txtEmailAddress.value) == ""){
		alert("Email Address is required.");
		form.txtEmailAddress.focus();
		return;
	}
	if (IsEmail(Trim(form.txtEmailAddress.value)) == false){
		alert("Email Address is not formatted properly.");
		form.txtEmailAddress.focus();
		return;
	}	
	if (Trim(form.txtPassword.value) == ""){
		alert("Password is required.");
		form.txtPassword.focus();
		return;
	}	
    //Then submit the email and password to the incorp.com server for the login:

		document.frmMain.target = "_self";    
		document.frmMain.action = "http://www.incorp.com/frmLoginHub.aspx";
		document.frmMain.submit();  
     
}

//------------------------------------------------------------------------------------------------------------------------------------------------	
function Client_BeforeSendPassword(){	

	//Check to make sure required fields are filled in:
	if (Trim(document.frmMain.txtEmailAddress.value) == ""){
		alert("Email Address is required.");
		document.frmMain.txtEmailAddress.focus();
		return;
	}
	if (IsEmail(Trim(document.frmMain.txtEmailAddress.value)) == false){
		alert("Email Address is not formatted properly.");
		document.frmMain.txtEmailAddress.focus();
		return;
	}		
	
	//Initialize the pipeline:
	GetPipeLineById("").Initialize("Client_AfterSendPassword", "Client_SendPassword");	

}
//------------------------------------------------------------------------------------------------------------------------------------------------
function Client_AfterSendPassword(){

	var result = GetPipeLineById("").GetResult();
	
	if (result == "0"){
	
		alert("Your password was successfully sent to your email account.");
	
	}
	else {
	
		alert(result);
	
	}

}
//------------------------------------------------------------------------------------------------------------------------------------------------
function Public_Link_OnMouseOut(link){

	link.style.color = "#2070BD";	
	
}
//------------------------------------------------------------------------------------------------------------------------------------------------
function Public_Link_OnMouseOver(link){	
	
	link.style.color = "#C00000";	
}

//------------------------------------------------------------------------------------------------------------------------------------------------
function Trim(value){

	value = value.toString();

	return LTrim(RTrim(value));	
}
//------------------------------------------------------------------------------------
function LTrim(value){	
	var space = value.search( /^\s*(\S.*)/ );
	return ( ( space == -1 ) ? "" : RegExp.$1 );
}
//------------------------------------------------------------------------------------
function RTrim(value){	
	var space = value.search( /\s+$/ );
	return ( ( space == -1 ) ? value : value.substr( 0, space ) );
} 
//--------------------------------------------------------------------------------------------------------------------------------------------------
function IsEmail(value){

	if (value == ""){
		return true;
	}	
	
    //Check for an @ symbol:    
    if (value.indexOf("@") == -1){
        return false;
    }
    //Check for more than 1 @ symbol:    
    if (value.indexOf("@") != value.lastIndexOf("@")){
        return false;
    }
    
    //Check for an . symbol after @ symbol:    
    if (value.lastIndexOf(".") < value.indexOf("@")){
        return false;
    }
    
    //Check for an empty " " string:    
    if (value.indexOf(" ") != -1){
        return false;
    }
    
    //Check for invalid symbols:
    if (value.indexOf("*") != -1){
        return false;
    }
    if (value.indexOf("%") != -1){
        return false;
    }
    if (value.indexOf(",") != -1){
        return false;
    }
    if (value.indexOf(";") != -1){
        return false;
    }
    if (value.indexOf("'") != -1){
        return false;
    }
    if (value.indexOf("\"") != -1){
        return false;
    }
    if (value.indexOf(":") != -1){
        return false;
    }
    return true;
}






