
// The following lines needs to be edited each time we move from unix to localhost!!!
var cgiApplyPath = '/cgi-sys/cgiwrap/vedic/apply/';
var cgiApplySecurePath = 'https://ssl15.pair.com/cgi-sys/cgiwrap/vedic/apply/';
var baseDir="http://www.vedicvibration.com";
var secureBaseDir="https://ssl15.pair.com/vedic";
//var templatePath = '/mvvt/templates/';

finalizeOn = new Image();
finalizeOn.src = "/images/finalize-on.gif";
finalizeOff = new Image();
finalizeOff.src = "/images/finalize-off.gif";
reviewBOn = new Image();
reviewBOn.src = "/images/review-on.gif";
reviewBOff = new Image();
reviewBOff.src = "/images/review-off.gif";

function loadSubmits(){loadSubmitsI(false)}
function loadSubmitsI(isSecure)
{
var myBase
if (isSecure) myBase=secureBaseDir
else myBase=baseDir
SubmitOn = new Image();
SubmitOn.src = myBase+"/images/submit-on.gif";
SubmitOff = new Image();
SubmitOff.src = myBase+"/images/submit-off.gif";
CancelOn = new Image();
CancelOn.src = "/images/cancel-on.gif";
CancelOff = new Image();
CancelOff.src = "/images/cancel-off.gif";
}

function ReadCookie (CookieName) {
  var CookieString = document.cookie;
  var CookieSet = CookieString.split (';');
  var SetSize = CookieSet.length;
  var CookiePieces
  var ReturnValue = "";
  var x = 0;

  for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {

    CookiePieces = CookieSet[x].split ('=');

    if (CookiePieces[0].substring (0,1) == ' ') {
      CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
    }

    if (CookiePieces[0] == CookieName) {
      ReturnValue = CookiePieces[1];
		return ReturnValue;
    }
  }
  return "";
}
//*******************************************************************
function movepic(img_name,img_src) {
document[img_name].src=eval(img_src+".src");
}
//*******************************************************************
function showSessionButtons()
{
	showSessionButtonsInner(1);
}
//*******************************************************************
function showSessionButtonsInner(doTr)
{
	var sid = ReadCookie('sid');
	if (sid != null && sid.length > 0)
	{	
		if (doTr==1){document.write("<TR>");}
		document.write("<TD bgcolor='#66cc66' HEIGHT='65'><TABLE width='100%'><TR><TD>");
		var sif = ReadCookie('sif');
		var mUrl,mAlt;
		document.write("<A HREF='"+cgiApplyPath+"rctg.pl?ac=ra' onmouseover=\"movepic('reviewB','reviewBOn')\" onmouseout=\"movepic('reviewB','reviewBOff')\"><IMG name='reviewB' SRC='/images/review-off.gif' WIDTH='100' HEIGHT='36' BORDER=0 ALT='Review Your application'></A></TD>");
		document.write("</TD><TD align='center'>"+getHeaderNameFromCookie()+"</TD><TD align='right'><A HREF='");
		if (sif != null && sif == 'personal' || sif == 'finance')
		{
			var locSel = ReadCookie('ls');
			var	myRe= /.*(..)/i;
			var cin;
			cin = myRe.exec(locSel);
			mUrl=cgiApplySecurePath+"prefinance.pl?lssid="+cin[1]+sid;
			mAlt="Finalize";
		}
		else
		{
			mUrl="/apply/personal.html";
			mAlt="Add your personal information";
		}
		document.write(mUrl+"' onmouseover=\"movepic('finalize','finalizeOn')\" onmouseout=\"movepic('finalize','finalizeOff')\"><IMG name='finalize' SRC='/images/finalize-off.gif' WIDTH='100' HEIGHT='36' BORDER=0 ALT='"+mAlt+"'></A>");
		document.write("</TD></TR></TABLE></TD>");
		if (doTr==1){document.write("</TR>");}

	} 
}
//*******************************************************************
function WriteCookie (cookieName, cookieValue, expiry) 
{
var expDate = new Date();
if(expiry){
	expDate.setTime (expDate.getTime() + expiry);
	document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + expDate.toGMTString()+";path=/";
}else{
	document.cookie = cookieName + "=" + escape (cookieValue)+";path=/";}
}
//*******************************************************************
function getHeaderNameFromCookie()
{
	var name = getNameFromCookie();
	if (name.length < 1)
	{
		name = "&nbsp;";
	}else
	{
		name = '<B><FONT COLOR="#FFFFFF" size="4">Welcome<BR>'+name+"</FONT></B>";
	}
	return name;
}
//*******************************************************************
function getNameFromCookie()
{
	var name = getTitleNameFromCookie()+" "+getFirstNameFromCookie()+" "+getLastNameFromCookie();
	if (name.length < 3){name="";}
	return name;
}
//*******************************************************************
function getNameInstFromCookie()
{
	var name=getNameFromCookie();
	if (name.length>0){document.write(name+" - ");}
}
//*******************************************************************
function getTitleNameFromCookie(){return getPartNameFromCookie(0);}
function getFirstNameFromCookie(){return getPartNameFromCookie(1);}
function getLastNameFromCookie(){return getPartNameFromCookie(2);}
//*******************************************************************
function getPartNameFromCookie(index)
{
var name=ReadCookie('name');
if (name==null){return "";}
name=unescape(name);
if (name.length<3){return "";}
var nsa = name.split('~');
return nsa[index];
}
//*******************************************************************
function writeNameCookie(theForm)
{
if('undefined'==typeof(theForm.ptitle)){return;}
var name=trimMe(theForm.ptitle.value)+"~"+ trimMe(theForm.firstName.value)+"~"+trimMe(theForm.lastName.value);
if(name.length>2){WriteCookie("name",name);}
}
//*******************************************************************
function trimMe(inS)
{
	while(inS.substring (0,1)==' '||inS.substring(0,1)=='\t'){inS=inS.substring (1);}
	while(inS.substr(inS.length-1,1)==' '||inS.substr(inS.length-1,1)=='\t'){inS=inS.substr(0,inS.length-1);}
	return inS;
}
//*******************************************************************
function showInitialInfo()
{
	var name = getNameFromCookie();
	if (name.length < 1)
	{
	document.write("<TR><TD bgcolor=\"#339966\"><FONT COLOR=\"#FFFFFF\"><B>Your name</B></FONT></TD></TR>");
	document.write("<TR><TD><TABLE border=0>");
	document.write("<TR valign=\"bottom\">");
	document.write("<TD><IMG SRC=\"/images/dtclr.gif\" WIDTH=\"80\" HEIGHT=\"26\" ALT=\"Title\"><B>Title</B></TD>");
	document.write("<TD valign=\"bottom\">&nbsp;&nbsp;<B>First Name</B></TD>");
	document.write("<TD valign=\"bottom\">&nbsp;&nbsp;<B>Last Name</B></TD></TR>");
	document.write("<TR valign=\"bottom\"><TD><IMG SRC=\"/images/dtclr.gif\" WIDTH=\"80\" HEIGHT=\"26\" ALT=\"Title\"><INPUT TYPE=\"text\" NAME=\"ptitle\" maxlength=\"5\" size=\"5\"></TD>");
	document.write("<TD valign=\"bottom\">&nbsp;&nbsp;<INPUT TYPE=\"text\" NAME=\"firstName\" maxlength=\"25\"></TD>");
	document.write("<TD valign=\"bottom\">&nbsp;&nbsp;<INPUT TYPE=\"text\" NAME=\"lastName\" maxlength=\"25\"></TD>");
	document.write("</TR></TABLE></TD></TR>");
	}
}
//*******
function putApplySubmit() {putApplySubmitI(false)}
function putApplySubmitI(isSecure)
{
var myBase
if (isSecure) myBase=secureBaseDir
else myBase=baseDir
if(navigator.appName.indexOf('Microsoft')==-1 && navigator.userAgent.indexOf('Firefox')==-1)
//document.write("<A HREF=\"#\" onclick=\"testInputsAndSubmit(document.me)\" onmouseover=\"movepic('Submit1','SubmitOn')\" onmouseout=\"movepic('Submit1','SubmitOff')\"><IMG name=\"Submit1\"  SRC=\"/images/submit-off.gif\"  WIDTH=\"100\" HEIGHT=\"36\" BORDER=\"0\"></A>");
document.write("<INPUT TYPE=\"submit\" VALUE=\"SUBMIT\" onclick=\"testInputsAndSubmit(document.me)\">");
else
document.write("<IMG name=\"Submit1\" onclick=\"testInputsAndSubmit(document.me)\" onmouseover=\"movepic('Submit1','SubmitOn')\" onmouseout=\"movepic('Submit1','SubmitOff')\" SRC=\""+myBase+"/images/submit-off.gif\"  WIDTH=\"100\" HEIGHT=\"36\" BORDER=\"0\">");
}


