/*********************************************************
*	Name:			NOF.js
*	Purpose:	This is a common javascript file which contains the various function.
*
*	Change History
*	Date								Author								Description:
*	--------		--------		-----------------------------
*	12-Jan-2005				AquimR									Created
**********************************************************/

	function toggleText(ArrIndex){		
		if (typeof(ToggleAll[0]) != 'undefined'){		
			if(ToggleAll[ArrIndex].innerText == "Collapse All"){				
				for(i=0; i<ToggleAll.length; i++)
				{
						ToggleAll[i].innerText = "Expand All";					
						toggleAll(true, i);								
				}						
			}
			else {		
				for(i=0; i<ToggleAll.length; i++)
				{
						ToggleAll[i].innerText = "Collapse All";					
						toggleAll(false, i);								
				}		
			}				
		}else{
			if(ToggleAll.innerText == "Collapse All"){
				ToggleAll.innerText = "Expand All";
				toggleAll(true, 0);							
			}
			else {	
				ToggleAll.innerText = "Collapse All";
				toggleAll(false, 0);							
			}				
		}
			return true;
	}
	
	function toggleAll(bool, ArrIndex){		
		
		if(bool==true)
			value="none";
		else
			value="block";			
		if (typeof(Features[0]) != 'undefined')
		{
			Features[ArrIndex].style.display = value;		
			Finishes[ArrIndex].style.display = value;						
			ProductLineOffer[ArrIndex].style.display = value;
			Accessories[ArrIndex].style.display = value;	
			RelatedProducts[ArrIndex].style.display = value;	
			Sustainability[ArrIndex].style.display = value;
			Documentation[ArrIndex].style.display = value;		
		}else{					
			Features.style.display = value;		
			Finishes.style.display = value;
			ProductLineOffer.style.display = value;			
			Accessories.style.display = value;					
			RelatedProducts.style.display = value;			
			Sustainability.style.display = value;
			Documentation.style.display = value;		
		}
		
		return true;
	}
		     
	function toggleTab(index, ArrIndex){				
		var tab;		
		//toggleAll(true, ArrIndex);		
		if (typeof(Features[0]) != 'undefined')
		{			
			for(i=0; i<Features.length; i++)
				{						
					switch(index){
						case 0:
							tab=eval(Features[i]);
							break;
						case 1:				
							tab=eval(Finishes[i]);
							break;				
						case 2:
							tab=eval(ProductLineOffer[i]);
							break;						
						case 3:
							tab=eval(Accessories[i]);
							break;
						case 4:
							tab=eval(RelatedProducts[i]);
							break;						
						case 5:
							tab=eval(Sustainability[i]);
							break;	
						case 6:
							tab=eval(Documentation[i]);
							break;
					}					
					if(tab.style.display=="block"){						
						tab.style.display="none";
						for(j=0; j<ToggleAll.length; j++)
							{									
								ToggleAll[j].innerText = "Expand All";														
							}						
						}else{													
							tab.style.display="block";							
							if (true == CheckOpenClose()) {
								for(j=0; j<ToggleAll.length; j++)
									{									
										ToggleAll[j].innerText = "Collapse All";														
									}						
							}
						}						
			}
		}
		else
		{
			switch(index){
				case 0:
					tab=eval(Features);
					break;
				case 1:				
					tab=eval(Finishes);
					break;				
				case 2:
					tab=eval(ProductLineOffer);
					break;						
				case 3:
					tab=eval(Accessories);
					break;
				case 4:
					tab=eval(RelatedProducts);
					break;						
				case 5:
					tab=eval(Sustainability);
					break;	
				case 6:
					tab=eval(Documentation);
			}
			if(tab.style.display=="block"){						
				tab.style.display="none";				
				ToggleAll.innerText = "Expand All";														
			}else{													
					tab.style.display="block";							
					if (true == CheckOpenClose()) {
						ToggleAll.innerText = "Collapse All";																		
					}
			}						
		}		
		return true;		
	}	
	
	function CheckOpenClose(){				
		var tab;				
		if (typeof(Features[0]) != 'undefined')
		{	
			tab=eval(Accessories[0]);			
			if(tab.style.display=="" || tab.style.display=="none")
					return false;
			tab=eval(Features[0]);						
			if(tab.style.display=="" || tab.style.display=="none")
					return false;
			tab=eval(Finishes[0]);
			if(tab.style.display=="" || tab.style.display=="none")
					return false;
			tab=eval(RelatedProducts[0]);						
			if(tab.style.display=="" || tab.style.display=="none")
					return false;
			tab=eval(ProductLineOffer[0]);						
			if(tab.style.display=="" || tab.style.display=="none")
					return false;
			tab=eval(Sustainability[0]);
			if(tab.style.display=="" || tab.style.display=="none")
					return false;			
			tab=eval(Documentation[0]);
			if(tab.style.display=="" || tab.style.display=="none")
					return false;								
		}else{
			tab=eval(Accessories);
			if(tab.style.display=="" || tab.style.display=="none")
					return false;
			tab=eval(Features);
			if(tab.style.display=="" || tab.style.display=="none")
					return false;
			tab=eval(Finishes);
			if(tab.style.display=="" || tab.style.display=="none")
					return false;
			tab=eval(RelatedProducts);						
			if(tab.style.display=="" || tab.style.display=="none")
					return false;
			tab=eval(ProductLineOffer);						
			if(tab.style.display=="" || tab.style.display=="none")
					return false;
			tab=eval(Sustainability);
			if(tab.style.display=="" || tab.style.display=="none")
					return false;			
			tab=eval(Documentation);
			if(tab.style.display=="" || tab.style.display=="none")
					return false;			
		}					
		return true;				
	}
	
	/*Email Validation */
	
function checkemail(objName){	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	var str=document.all(objName).value;
	var arr_str = str.split(",");
	
	var part_num=0;
	var CheckReturn = true
	
	while (part_num < arr_str.length)
	{		
		if (filter.test(trimAll(arr_str[part_num])) == false){						
			CheckReturn = false
			break;
		}		
		part_num+=1;
  }	
	if (CheckReturn == true){
		return true;
	}else{		
		return false;
	}
}

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 chkDate(objName) {	
	var strDatestyle = "US"; //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "01";
	strMonthArray[1] = "02";
	strMonthArray[2] = "03";
	strMonthArray[3] = "04";
	strMonthArray[4] = "05";
	strMonthArray[5] = "06";
	strMonthArray[6] = "07";
	strMonthArray[7] = "08";
	strMonthArray[8] = "09";
	strMonthArray[9] = "10";
	strMonthArray[10] = "11";
	strMonthArray[11] = "12";	
	strDate = objName; //datefield.value;
	if (strDate.length < 1) {
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++){
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}else{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
				booFound = true;
		}
	}
if (booFound == false) {
	if (strDate.length>5) {
		strDay = strDate.substr(0, 2);
		strMonth = strDate.substr(2, 2);
		strYear = strDate.substr(4);
		}
}

if (typeof(strYear) == "string"){
	if (strYear.length == 2) {
			if(parseInt(strYear) > 90) {
					strYear = '19' + strYear;     
			}else {
					strYear = '20' + strYear;
			}
	}
}
// checking for year should be within 3000
if (parseInt(strYear) > 3000 ) {
//alert("That date is invalid.  Please try again.");
return false;
}

// checking for year should be greater than 1900
if (parseInt(strYear) < 1970 ) {
//alert("That date is invalid.  Please try again.");
return false;
}


// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;


}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
	err = 8;
	return false;
	}
	if (LeapYear(intYear) == true) {
		if (intday > 29) {
			err = 9;
			return false;
		}
	}
	else {
		if (intday > 28) {
			err = 10;
			return false;
			}
	}

}

if (strDatestyle == "US") {
if (intday <10){
intday = "0" + intday
}
datefield.value = strMonthArray[intMonth-1] + "/" + intday+"/" + strYear;
}
else {
//datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
}


return true;
}

function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

	var myPage;
	function OpenWindow(sImagePath)
	{		
		var sURL
		sURL = "/app/frms/previewimage.aspx?ImagePath=" + sImagePath
		
		x = (640 - 350)/2, y = (480 - 120)/2;
		if (screen) {	
			y = (screen.availHeight - 120)/2;
			x = (screen.availWidth - 312)/2;
		}
				
		if (!myPage || myPage.closed){				
			myPage = window.open(sURL,"_blank","height=300, width=350, scrollbars=yes, status=no,toolbar=no,menubar=no, top="+y+",left="+x);							
		}
		else {		
			myPage.location.href = "/app/frms/previewimage.aspx?ImagePath=" + sImagePath
			myPage.focus();			
		}
	}
	
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;
}


//--------------------------------
//METHOD NAME : SetFocusEditForm
//PARAMS :oFormName
//			oFormName     :Its the ID of the Form whose First Editable field should be focused 
//PURPOSE : Sets the Focus on the first Editable field of the Form name  Passed 
//			
//		
//--------------------------------
function SetFocusEditForm(oFormName,oFrmElement)
{//alert(oFrmElement)
	if (oFrmElement != null)
	{
		oFrmElement.focus();
		return;   
	}

    var frmParams =  oFormName
/* if (frmParams == null)
    return;*/
        
    var frmElms = frmParams.elements;
    var i,frmElmType;
    
    for(i=0;i<frmElms.length;i++)
    { 
        frmElmType = frmElms[i].type;        
        //alert(frmElms[i].isDisabled + "\n frmElmType=" +  frmElmType)
        if(frmElms[i].isDisabled == false)
        {   if((frmElmType.indexOf('select') != "-1" || frmElmType.indexOf('text') != "-1" || frmElmType.indexOf('button') != "-1" )  ){// 
                    //Note   : Focus method is intentionally called twice.
                    //Reason : Doesn't set focus properly if element type is "text"                    
                    frmElms[i].focus();
                    frmElms[i].focus();
                // alert(frmElms[i].name);
                    return;
            }
        }
    
    }
}

// Function for integer checking
function isInteger (s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

// Function to check single character is number or not
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

// Function to open popup window according to the active survey
// Change By : Parimal Patel
// Date      : 18-Aug-2005


//Function to open window and logout the user

function onClose()
{          
  if(window.screenTop>10000)
  {
              //Logout();
  }
}

function Logout()
{
    x = (640 - 350)/2, y = (480 - 120)/2;
    if (screen) 
    {      
		y = (screen.availHeight - 120)/2;
		x = (screen.availWidth - 312)/2;
	}		
	window.open('/Survey/CallPopup.aspx','','menubar=no,titlebar=no,toolbar=no,resizable=yes, scrollbars=yes,height=50,width=50,left=150,top=50');
}

      //window.onunload= function (e) {alert("Unload event"); };				
//      window.onunload = function (e) {window.open('/app/Survey/CallPopup.aspx',//'CallCommonSurvey')};				//,'width=680,height=800,scrollbars=yes,resizable=no')};				
      /*function openwin()
      {
					window.open('Tier1SurveyPopup.aspx','Tier1popupwindow','width=280,height=100,scrollbars=yes,
					resizable=no,left=350,top=150');
      }*/
