﻿// JScript File
function PrintOrderPage() 
{ 

   window.print() 
}
/////////Constants To open Popup


PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Set the value in milliseconds to close the window
// automatically after this amount of time
// 1000 milliseconds equals one second

var closeTime =600000;

// Do not edit below this line...
// ================================
var closeCode = ";setTimeout('self.close()',"+closeTime+")";
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='mywindow,scrollbars=0,width=200,height=200'

///////////////////
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');

writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height); }');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["Product"].width;');writeln('window.innerHeight=document.images["Product"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()'+closeCode+'">')
else writeln('</head><body bgcolor=000000 scroll="yes" onload="reSizeToImage();doTitle();self.focus()'+closeCode+'" onblur="self.close()">');
writeln('<img name="Product" src='+imageURL+' style="display:block"></body></html>');
close();		
}}

function openPopupWindow()
{
var wnd= window.open("cvc.html","cvc","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=600,width=800");
wnd.moveTo(10,10);
wnd.focus(); 

}

function goImgWin() 
{
     var myWidth =600,myHeight = 600, origLeft =100,origTop = 50;
     var Image1 = document.getElementById(JS_CurrentImage);
     var myImage = Image1.src;
     myHeight += 24;
     myWidth += 24;    
    // Change Path
    var arrPath = myImage.split("/");   
    var i;
    var path="";
    for(i=0; i<arrPath.length-1; i++)
    {
        if(arrPath[i]=="Product_View")
        {
          continue;
        }
        path = path+ arrPath[i]+"/";
    }    
    path = path+ arrPath[i];   
    myImage = path;    
    popImage(myImage,"Product");   
}

function PrintThisPage() 
{ 
var sOption="toolbar=no,location=no,directories=no,menubar=no,"; 
       sOption+="scrollbars=yes,width=1,height=1,left=1,top=1"; 
    window.open("printcontract.aspx","",sOption); 

/*   var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
       sOption+="scrollbars=yes,width=1,height=1,left=1,top=1"; 

   var sWinHTML = document.getElementById('ctl00_ContentPlaceHolder1_divContract').innerHTML; 
   
   var winprint=window.open("","",sOption); 
       winprint.document.open(); 
       winprint.document.write('<html><body'); 
       winprint.document.write(sWinHTML);     
       winprint.document.write('</body></html>'); 
       winprint.document.close(); 
       winprint.focus();
      window.print(); 
      winprint.close();
  */
}
function setRateOfInterest(ddDownPayment)
{
    var ctlToValidate = document.getElementById(ddDownPayment);
    var arrRate = new Array("-","12.9","11.9","10.9","8.9","5% Discount"); 
    if (ctlToValidate.options[ctlToValidate.selectedIndex].value != "-1")
	{
	    var ctlToValidate1 = document.getElementById("ctl00_ContentPlaceHolder1_txtROI");
		ctlToValidate1.value = arrRate[ctlToValidate.selectedIndex];
		
		if(ctlToValidate.selectedIndex ==5)
		   document.getElementById("ctl00_ContentPlaceHolder1_txtMortgage").value =0;
	}
}

function selectRateOfInterest(ddDownPayment, txtRoI)
{
    var ctlToValidate = document.getElementById(ddDownPayment);
    var arrRate = new Array("-","12.9","11.9","10.9","8.9","5% Discount"); 
    if (ctlToValidate.options[ctlToValidate.selectedIndex].value != "-1")
	{
	    var ctlToValidate1 = document.getElementById("ctl00_ContentPlaceHolder1_txtROI");
	   
		ctlToValidate1.value = arrRate[ctlToValidate.selectedIndex];
		
		if(ctlToValidate.selectedIndex ==5)
		   document.getElementById("ctl00_ContentPlaceHolder1_txtMortgage").value =0;
	}
}
function SetImage(img)
{
    var imgName = img;    
    var the_length = imgName.length;
    var last_char = imgName.charAt(the_length-1);
    ShowCaption(last_char);
    var ImageFrom = document.getElementById("ctl00_ContentPlaceHolder1_"+img);
    var ImageTo = document.getElementById("ctl00_ContentPlaceHolder1_Image1");   
    var arrPath = ImageFrom.src.split("/");   
    var i;
    var path="";
    for(i=0; i<arrPath.length-1; i++)
    {
        if(arrPath[i]=="Product_Thumbs")
        {
           arrPath[i] = "Product_View";
        }
        path = path+ arrPath[i]+"/";
    }    
    path = path+ arrPath[i];   
    ImageTo.src = path;
    ShowImageBorder(last_char);
}
function ShowCaption(pId)
{
    var prefix = "ctl00_ContentPlaceHolder1_lblDBCaption"; 
    for(i=1;i<=8;i++)
        document.getElementById("ctl00_ContentPlaceHolder1_lblDBCaption" + i).style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_lblDBCaption" + pId).style.display = "inline"; 
}
function ShowImageBorder(pId)
{
    var prefix = "ctl00_ContentPlaceHolder1_Img"; 
    for(i=1;i<=8;i++)
    {
        if(document.getElementById("ctl00_ContentPlaceHolder1_Img" + i) != null)
        document.getElementById("ctl00_ContentPlaceHolder1_Img" + i).style.border = "solid 1px black";
    }
    document.getElementById("ctl00_ContentPlaceHolder1_Img" + pId).style.border = "solid 2px #790707";
}
function ValidateLength(txtPresentLOP, txtLen)
{
	var PLOP = document.getElementById(txtPresentLOP);
	if(PLOP.value.length >= txtLen)
		return false;
	
	return true;
}
function ShowMessage()
{
    alert("Password has been changed.");
}
function format(input)
{	
    var num = input.value.replace(/\,/g,'');
	num = num.replace(/,,/g,'');
	var num1 = roundNumber(num,2);
	
	//var num1 = num;
	num1 = parseFloat(num1);
	
	if(num1!=0)
	{
		if(!isNaN(num))
		{
				while(num.indexOf('0') == 0)
				{	
					num = num.substring(1,num.length);
				}
			
			if(num.indexOf('.') > -1)
			{ 
				num = num.split('.');
				num[0] = num[0].toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'');
				
				if(num[1].length > 2)
					num[1] = num[1].substring(0,num[1].length-1);
				
				var tmpVal = num[0]+ '.' + getDecimalVal(roundNumber('.'+num[1],2).toString());  
				input.value = tmpVal;
			} 
			else
			{ 
				input.value = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'') 
			}
		}

		else
		{ 
			input.value = input.value.substring(0,input.value.length-1);
		}
	}
}
function roundNumber(numberfield, rlength) 
{
	if(parseFloat(numberfield) == 0)
		return ".00";
		
	var newnumber = Math.round(numberfield*Math.pow(10,rlength))/Math.pow(10,rlength);
	numberfield = newnumber;
	return numberfield;
	
}
function getDecimalVal(val1)
{
	if(val1.indexOf('.') > -1)
		return val1.split('.')[1];
	else
		return val1;
}
function show(Url)
{
	window.open(Url,"ProductImage","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=500,width=500");
}
function validateEmail(email)
{			 
    // This function is used to validate a given e-mail 
	// address for the proper syntax
	if (trim(email) == ""){
		return false;
	}	 
	
	posOfAtSign = email.indexOf(" ",1)
	if (posOfAtSign > -1){
		return false;
	}
	 
	posOfAtSign = email.indexOf("@",1)
	if (posOfAtSign == -1){
		return false;
	}
	if (email.indexOf("@",posOfAtSign+1) != -1){
		return false;
	}
	posOfPeriod = email.indexOf(".", posOfAtSign)
	if (posOfPeriod == -1){
		return false;
	}
	if (posOfPeriod+2 > email.length){
		return false;
	}
	return true
}

function trim(s) 
{
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}
	

function fn_NumericTextbox(e,txt)
{	

    var evt=(e)?e:(window.event)?window.event:null;
    if(evt)
        { 
            var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 
            if(key!="8")
            {
                var str=txt;						
                if (!fn_isNumeric(str.value))			
                {
	                str.value="";					
                }
            } 
        }
}

//  check for valid numeric strings	
function isNumeric(strString)
 {
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;
	    //  test strString consists of valid characters listed above
	    for (i = 0; i < strString.length && blnResult == true; i++)
		    {
			    strChar = strString.charAt(i);
			    if (strValidChars.indexOf(strChar) == -1)
        		    {
		    		    blnResult = false;
				    }
		    }
    return blnResult;
}

function isFloat(s){
	var i;
	var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
  
	if (reFloat.test(s) == false)
		return false;

    // All characters are numbers.
    return true;
}

/*===============================================*/
//Date Related functions
/*===============================================*/
function LeapYear(intYear) 
 {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	}
	else { 
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

function fn_checkDate(dt)
{
	var reg = new RegExp("[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}$");
	if(reg.test(dt))
	{
		var datepart = dt.split("/");
		for(i=0;i<datepart.length;i++)
			datepart[i] = parseInt(parseFloat(datepart[i]));
		if(datepart[0] > 31 || datepart[1] > 12)
			return false;
		else if((datepart[1] == 4 || datepart[1] == 6 || datepart[1] == 9 || datepart[1] == 11) && datepart[0] == 31)
			return false;	
		else if(datepart[1] == 2)
		{
			if(datepart[0] > 29)
				return false;
			if(!LeapYear(datepart[2]) && datepart[0] == 29)
				return false;
		}
		return true;						
	}
	return false;			
	
}

/*===============================================*/