//  Application:   SQPS_v02_02_03 - portal implementation
//	common.jsp - common javascript functions 

var myfrm;
var PDFwindow = null;
var mywindow = window.document;


// JavaScript Document

		// scroll to top of iframe when launched in portal window
		function scrolltop(){
		window.scrollTo(0,0);
		}

		function leftTrim(sString) 
		{
		while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
		return sString;
		}

		function rightTrim(sString) 
		{
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
		sString = sString.substring(0,sString.length-1);
		}
		return sString;
		}

		function trimAll(sString) 
		{
		while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
		sString = sString.substring(0,sString.length-1);
		}
		return sString;
		}


		function validateEmail() {
			//Validating the email field
			var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
			var emailvalue = document.contact.email.value;
			
			emailvalue = trimAll(emailvalue)
			
			if (!emailvalue.length==0 && !emailvalue.match(re)){
				alert(inputerrormsg);
				document.contact.email.focus();
			}else{
				document.contact.email.value = emailvalue;
				document.contact.submit();
			}			
		}

		function openWindow(url) {
			var strFeatures = "resizable,width=500,height=570,location=off,menubar=off,scrollbars,toolbar=off,";
			
			if (document.all) {
				strFeatures += "left=100,top=50";
			} else {
				strFeatures += "screenX=100,screenY=50";
			}
			dwin=window.open(url,"help",strFeatures);
			dwin.focus();
		}

		function openFeedback(url) {
			var strFeatures = "resizable,width=500,height=570,location=off,menubar=off,scrollbars,toolbar=off,";
			
			if (document.all) {
				strFeatures += "left=100,top=50";
			} else {
				strFeatures += "screenX=100,screenY=50";
			}
			dwin=window.open(url,"Feedback",strFeatures);
			dwin.focus();
		}

		function openTracking(url) {
			var strFeatures = "resizable,width=700,height=480,location=off,menubar=off,scrollbars,toolbar,";
			if (document.all) {
				strFeatures += "left=100,top=50";
			} else {
				strFeatures += "screenX=100,screenY=50";
			}
			dwin=window.open(url,"tracking",strFeatures);
			dwin.focus();
		}

		function openMap(url,sWebsiteParam,sWebsiteValue, sTitleParam,sTitleValue,sLanguageParam,sLanguagevalue,sParam1, sParam1Value,sParam2, sParam2value) {
			//dcsMultiTrack(sWebsiteParam,sWebsiteValue,sLanguageParam,sLanguagevalue,sParam1, sParam1Value,sParam2, sParam2value);
			var strFeatures = "resizable,width=770,height=570,location=off,menubar,scrollbars,toolbar,";
			if (document.all) {
				strFeatures += "left=100,top=50";
			} else {
				strFeatures += "screenX=100,screenY=50";
			}
			dwin=window.open(url,"maplocation",strFeatures);
			dwin.focus();
		}


		function openPrint(url) {
			var strFeatures = "resizable,width=600,height=570,location=off,menubar,scrollbars,toolbar=off,";
			
			if (document.all) {
				strFeatures += "left=100,top=50";
			} else {
				strFeatures += "screenX=100,screenY=50";
			}
			dwin=window.open(url,"print",strFeatures);
			dwin.focus();
		}

// verify compare products on view list from
function verifyForm( form, max_number, one_item_text, max_item_text )
{
	var iChecked = 0 ;
	if (!form.ITEMLIST.length)
	{
		if (!form.ITEMLIST.checked) 
		{
			alert( one_item_text) ;
			return false;
		} else {
			//return true;
			form.submit();
		}
	} else {
			for( var i = 0 ; i < form.ITEMLIST.length ; i++ )
			{
				if( form.ITEMLIST[i].checked )
					iChecked++ ;
			
				if( iChecked > max_number )
				{
					alert( max_item_text + " " + max_number  ) ;
					return false ;
				}
			}
			if( iChecked < 1 )
			{
				alert( one_item_text ) ;
				return false ;
			}	
			//return true ;
			form.submit();
	}
}

// verify keyword search string for minimum number of characters in string
function CheckData(form,error_msg, minchar)

{
      var strAlertMessage = error_msg;

i=0;
	var string = form.SRCH.value;
	// remove the wildcard character before checking for minimum length
	string = string.replace(/\*/g,'');
	//form.SRCH.value = string
	if (string.length < minchar)
	{	
		alert(strAlertMessage);
		return false;
	}
	else 
	{
		return true;
	}
}

// reload frame if text size is changed in the browser
var defaultfontsize = 0

function getFontSize() {
	if (mywindow.defaultView && mywindow.defaultView.getComputedStyle) {
		return parseInt(mywindow.defaultView.getComputedStyle(mywindow.body,'').getPropertyValue("font-size"))
	}
	else if (mywindow.all && mywindow.body.currentStyle) {

		return parseInt(mywindow.body.currentStyle.fontSize)
	}
}

function check() {
	var currentsize = getFontSize()
	if (currentsize != defaultfontsize) {
		mywindow.location.reload(false);
	}
	defaultfontsize = currentsize
}

function checkfontsize() {
	var theInterval = 500
	if ((mywindow != null) && ((mywindow.defaultView && mywindow.defaultView.getComputedStyle) || (mywindow.all && mywindow.body.currentStyle))) {
		defaultfontsize = getFontSize();
		setInterval("check()",theInterval);
	}
}

//function to open windows for links other than PDFs
function OpenTrackingWindow(frm,pnum,category,referrer,url)
{
	var strFeatures = "resizable,width=500,height=570,location=off,menubar=off,scrollbars,toolbar=off,";
	//setting the hidden variables in the parent form
	frm.pnum.value = pnum;
	frm.category.value = category;
	frm.referrer.value = referrer;
	frm.target.value = url;
	//setting the global variable so that the form can be accessed by the 
	//popup window
	myfrm = frm;
	
	//open the popup.html which posts the form to the metrics url
	var objWindow = window.open('popup.html', 'popup', strFeatures);
	objWindow.focus();
}

//function to open windows for links to PDFs
function OpenPDFWindow(frm,pnum,category,referrer,url)
{
	var strFeatures = "resizable,width=500,height=570,location=off,menubar=off,scrollbars,toolbar=off,";
	//setting the hidden variables in the parent form
	frm.pnum.value = pnum;
	frm.category.value = category;
	frm.referrer.value = referrer;
	frm.target.value = url;
	//setting the global variable so that the form can be accessed by the 
	//popup window
	myfrm = frm;
	
	window.open('popup.html', '', strFeatures);
	
	/*if (PDFwindow == null)
	{
		PDFwindow=window.open('popup.html', 'popup', strFeatures);
	}
	else
	// when second PDF is selected and PDF window is active on minimized
	{
				if (PDFwindow.closed == true)
				{
				PDFwindow.close();
				PDFwindow=window.open('popup.html', 'popup', strFeatures);
				}
					
				if (PDFwindow.closed == false)
				{
				PDFwindow.close();
				PDFwindow=window.open('popup.html', 'popup', strFeatures);
				}
	}*/
}

function DownloadURL(frm,url, file)
{
	frm.target.value = url;
	frm.file.value = file;
	frm.action = "download.asp";
	frm.method = "POST";
	frm.submit();
}

function openLink(url,sWebsiteParam,sWebsiteValue, sTitleParam,sTitleValue,sLanguageParam,sLanguagevalue,sParam1, sParam1Value,sParam2, sParam2value, sScenarioParam1, sScenarioParam1Value, sScenarioParam2, sScenarioParam2Value) {
	dcsMultiTrack(sWebsiteParam,sWebsiteValue + 'TrackingLink', sTitleParam, "",sLanguageParam,sLanguagevalue,sParam1, sParam1Value, sParam2, sParam2value);
	dcsMultiTrack(sWebsiteParam,sWebsiteValue + 'TrackingLink', sTitleParam, "",sLanguageParam,sLanguagevalue,sScenarioParam1, sScenarioParam1Value, sScenarioParam2, sScenarioParam2Value);
	var strFeatures = "resizable,width=700,height=480,location,menubar,scrollbars,toolbar,";
	if (document.all) {
		strFeatures += "left=100,top=50";
	} else {
		strFeatures += "screenX=100,screenY=50";
	}
	dwin=window.open(url,"tracking",strFeatures);
	dwin.focus();
}

function openTracking(url,sWebsiteParam,sWebsiteValue, sTitleParam,sTitleValue,sLanguageParam,sLanguagevalue,sParam1, sParam1Value,sParam2, sParam2value) {
	dcsMultiTrack(sWebsiteParam,sWebsiteValue + 'TrackingLink',sTitleParam, "",sLanguageParam,sLanguagevalue,sParam1, sParam1Value,sParam2, sParam2value);
	var strFeatures = "resizable,width=700,height=480,location,menubar,scrollbars,toolbar,";
	if (document.all) {
		strFeatures += "left=100,top=50";
	} else {
		strFeatures += "screenX=100,screenY=50";
	}
	dwin=window.open(url,"tracking",strFeatures);
	dwin.focus();
}

function openPDFTracking(url,sWebsiteParam,sWebsiteValue, sTitleParam,sTitleValue,sLanguageParam,sLanguagevalue,sParam1, sParam1Value,sParam2, sParam2value) {
	dcsMultiTrack(sWebsiteParam,sWebsiteValue + 'TrackingLink',sTitleParam, "",sLanguageParam,sLanguagevalue,sParam1, sParam1Value,sParam2, sParam2value);
	var strFeatures = "resizable,width=700,height=480,location,menubar,scrollbars,toolbar,";
	if (document.all) {
		strFeatures += "left=100,top=50";
	} else {
		strFeatures += "screenX=100,screenY=50";
	}
	dwin=window.open(url,"",strFeatures);
	dwin.focus();
}


function validateZip( help)
		{
			var Number = document.form2.zip.value;
			var GoodChars = "0123456789"
			var i = 0

			for (i =0; i <= Number.length -1; i++)
			{
				if (GoodChars.indexOf(Number.charAt(i)) == -1)
				{
				alert(help);
				return false
				} // End if statement
			} // End for loop
			if ( Number.length < 5)
			{
				alert(help);
				return false;
			}
			return true
		}

