function validateTimings(FromHH,FromMM,FromSS,ToHH,ToMM,ToSS){

		var date1temp,date2temp,result;
		date1 = new Date();
		date2 = new Date();		
		
		date1temp = new Date('1/1/1900' + " " + FromHH+":"+FromMM+" "+FromSS);
		date1.setTime(date1temp.getTime());

		date2temp = new Date('1/1/1900' + " " + ToHH+":"+ToMM+" "+ToSS);
		date2.setTime(date2temp.getTime());

		// sets difference date to difference of first date and second date		
		
		result=(date1.getTime()<date2.getTime());
		
		return result;
}

function chkMendetory(txtObj)
{
	txtObj.value=txtObj.value.trim();
	if (txtObj.value=="")
	{
		txtObj.style.backgroundColor="#FFCCFF";
	}
	else
	{
		txtObj.style.backgroundColor="#FFFFFF";
	}
}

function chkPassword(str)
{
	if(!(str==""))
	{
		tomatch = /^[a-zA-Z0-9_]+$/;  //regular expression shortcut would be /^\w+$/
		if (!tomatch.test(str)) 
		{		
			return false
		}
		if(str.substring(0,1)=="_")
		{
			return false
		}
		for(inti=0;inti<str.length;inti++)
		{
			strCheck=str.substring(inti,inti+2);
			if(strCheck=="__")
			{
				return false
			}
		}
		return true
	}
}
function echeck(str)
{

if(!(str==""))
{
        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            return false
         }

         if (str.indexOf(" ")!=-1){
            return false
         }

          return true
     }
     
  }
function fnCheckNum(a)
{
	if(a<=47 || a>=58)
	{
		if(a!=10 && a!=13){
			event.keyCode="";
		}
	}

}

function open_popup(page) {
  window.open(page,'product', 'width=645,height=510, scrollbars=yes');
}

function fnCheckPrice(a, strFieldVal)
{
	var isPeriodExists;
	
	if(!(a==46)){
		fnCheckNum(a)
	}else{
	
		isPeriodExists=strFieldVal.indexOf('.')
	
		if(isPeriodExists>-1){	
			event.keyCode="";
			return;
		}
	}
}


function fnCheckSpecial(a)
{
	if(a==34){
		event.keyCode="";
	}
	
	if (!(a==39 || a==95 || a==46 || a==64 || a==45 || a==40 || a==41 || a==32 || (a>=48 && a<=57) || (a>=65 && a<=90) || (a>=97 && a<=122) || (a==13) || (a==10))){
		event.keyCode="";
	}
}
function fnCheckCVV2(a)
{
	
	if(a==34){
		event.keyCode="";
	}
	
	if (!(a==32 || (a>=48 && a<=57) || (a>=65 && a<=90) || (a>=97 && a<=122) || (a==13) || (a==10))){
		event.keyCode="";
	}
}
    
function fnCheckPhone(a){
	if(!(a==45 || a==40 || a==41 || (a>=48 && a<=57))){
		event.keyCode="";
	}
}
function fnCheckNValue(a){
	if(!(a>=48 && a<=57) && !(a==13) && !(a==46)){
		event.keyCode="";
	}
}  
function fnValidateQuote(a)
{
	if(a==39 || a==34)
	{
		event.keyCode="";
	}
}
function fnOpen(a){
	alert(a)
	window.location=a;
}

function FnSpecialChar(a){
		
	if(a==39)
	{
		event.keyCode="";
		alert("It can not have special character like. '");
	}
		
		return false;
}

function fnCheckWindow(a,b,c){
	var Q;
	var con;
	var selid;
	var seltype;
	selid="1"
	//seltype=c;
	var ret;
	con=b;
	Q=a;
	Q=Q.toUpperCase();
	 
	ret=showModalDialog("../hlp_Check_ID.asp?q="+Q+"&con="+con+"&seltype="+seltype,selid,"dialogHeight: 80px;,dialogWidth: 170px;,dialogTop: 400px; dialogLeft: 400px; center: Yes;,help: No; address:Yes;resizable: No; status: No;");
	 //ret=showModalDialog("../hlp_Check_ID.asp?q="+Q+"&con="+con+"&selid="+selid,"dialogHeight: 80px;,dialogWidth: 170px;,dialogTop: 400px; dialogLeft: 400px; center: Yes;,help: No; address:Yes;resizable: No; status: No;");
	//return false;
	
	if(ret=="2")
		return true;
	else{	
	
		eval(c).value="";
		eval(c).focus();	
		return false;
	}

}

function FnSpecialChar(a){
	
	if(a==39){
		event.keyCode="";
		alert("It can not have special character like. '");
	}
		
		return false;

}
//Function useful to remove "'" from value.    created on 09 Nov. By Sam
function ReplaceComma(V_str)
{
	var ss = V_str;		
	var re, r
	re= /'/g;
	r = ss.replace(re,"''");
	return(r);
}

String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing 
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function setsize(selfwin,win,lessx,lessy)
{	
   
	x=(win.screen.width / 2)-lessx;
	y=(win.screen.height /2)-lessy;
	
	win.moveTo(x,y);
	
	
		
	selfwin.opener=null;
}	
//Function useful to remove "'" from value.
function ReplaceComma(V_str){
	var ss = V_str;		
	var re, r
	re= /'/g;
	r = ss.replace(re,"''");
	return(r);
}

String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing 
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function validateKeyword(strKeyword){
	var strWord;
	if(strKeyword.indexOf(" ")>-1){
		return false;	
	}
	for(i=0;i<strKeyword.length;i++){
		strWord=strKeyword.charCodeAt(i);
		if (!(strWord==39 || strWord==95 || strWord==46 || strWord==64 || strWord==45 || strWord==40 || strWord==41 || (strWord>=48 && strWord<=57) || (strWord>=65 && strWord<=90) || (strWord>=97 && strWord<=122))){
			return false;			
		}

	}
	return true;
}

function selectAllOptions(objSelect){
	var totallength=objSelect.length;		
	for(i=0;i<totallength;i++){
		objSelect.options[i].selected=true; 
	} 		
}

function selectAllCheckboxes(objSelect){
	var totallength;		
	totallength=objSelect.length;
	
	for(i=1;i<totallength;i++){
		objSelect[i].checked=objSelect[0].checked; 
	} 		
}

function setMainCheckbox(chkMain, blnState){		
		
	if(!blnState)
		chkMain[0].checked=false;
		
}

function addURL(strConfigType,objText,objSelect){
	var blnValidate;
	var strText=objText.value;
	
	if(strText!=""){			
		blnValidate=validateOption(strText,strConfigType);
		if(!blnValidate){
			alert("Please enter valid option");			
			objText.focus();
			return;
		}
				
		var newOption=new Option();			
		newOption.value=strText;
		newOption.text=strText;
		objSelect.options[objSelect.length]=newOption;		
		
		for(i=0;i<objSelect.length;i++)
			objSelect.options[i].selected = false;
	
		newOption.selected=true;
		objText.value="";		
		objText.focus();
	}
}


//Begin-------------Himanshu 040107-----------------------

function addBuddyTemp(strConfigType,objText,objSelect){
	var blnValidate;
	var strText=objText.options[objText.selectedIndex].text;
	alert(strText);
	if(strText!=""){			
				
		var newOption=new Option();			
		newOption.value=strText;
		newOption.text=strText;
		objSelect.options[objSelect.length]=newOption;		
		
		for(i=0;i<objSelect.length;i++)
			objSelect.options[i].selected = false;
	
		newOption.selected=true;
		objText.value="";		
		objText.focus();
	}
}


function addBuddy(strConfigType,objText,objSelect){
	var selIndex = objText.selectedIndex;
	var t
	var k
	if (objSelect.length-1 > -1 )
	{
		t=objSelect.length
	}else
	{
		t=0;
	}
	
	if(selIndex > -1)
	{			
		for(k=objText.length-1;k>=0;k--)
		{				
			if(objText.options[k].selected) 
			{
				strText=objText.options[k].text;
				if (strText != "")
				{
					var newOption=new Option();
					newOption.value=strText;
					newOption.text=strText;
					objSelect.options[t]=newOption;
					t++
					
					for(i=0;i<selIndex;i++)
					newOption.selected=true;
					objText.value="";		
					objText.focus();
					objText.remove(k);
				}
			}				
		}		
	}	 
	 
}


function SynBuddy(objText,objSelect)
{
  var j
  var k
																  
  tot = objText.length-1
  for(k=tot;k>=0;k--)
  {	
	for(j=objSelect.length-1;j>=0;j--)
	{	
		if (objText.options[k].text == objSelect.options[j].text)
  		{
  			objText.remove(k);
  			j= -1
  		}
  	}
  }				
} 	
	


//End  -------------


function addTextURL(strConfigType,objText,objSelect){	
	if(event.keyCode==13){		
		addURL(strConfigType,objText,objSelect);
		event.keyCode=0;
		objText.focus();
		return;
	}
}

function removeURL(objSelect){
	var selIndex = objSelect.selectedIndex;
	if(selIndex > -1){
		for(i=objSelect.length-1;i>=0;i--){
			if(objSelect.options[i].selected)
				objSelect.remove(i);
		}
		if(objSelect.length > 0){
			if(objSelect.length>=selIndex+1){
				objSelect.options[selIndex].selected = true;
			}else{
				objSelect.options[selIndex-1].selected = true;
			}
		}
	}
}

function validateOption(strOption,strConfigType){
	var result;		
	if(strConfigType=="IM"){			
		result=validateEmail(strOption);
	}else if(strConfigType=="KW"){			
		result=validateKeyword(strOption);
	}else{
		result=true;			
	}		
	return result;
}

function enableOption(objChkOption,objTxtOption){
	if(!objChkOption.checked){
		objTxtOption.disabled=true;
	}else{
		objTxtOption.disabled=false;
		objTxtOption.focus();
		
	}	
		
}

function changeSelctedTPC(strValue, strRedirectPage){
	
	document.frmSearch.hidSelectedTPC.value=strValue;
	document.frmSearch.hidRequestedPage.value=strRedirectPage;
	document.frmSearch.action="changeSelTPC.asp";
	document.frmSearch.submit();
}

function selTPCSelected(objSelect, strSelPC){
var intCount;

	for(intCount=0;intCount<objSelect.length;intCount++){
			
		if(objSelect.options[intCount].value==strSelPC){
				
			objSelect.options[intCount].selected=true;
		}
	}	
}

function checkPasswordValidation(strPassword)
{
	var tomatch;
	var strCheck;
	tomatch = /^[a-zA-Z0-9_]+$/;  //regular expression shortcut would be /^\w+$/
	if (!tomatch.test(strPassword)) 
	{		
	 alert("Password can only contain letters, numbers, and underscores.");
	 return false;
	}
		
	if(strPassword.substring(0,1)=="_")
	{
		alert("The first character should not be Underscore.");
		return false;
	}
		
	for(inti=0;inti<strPassword.length;inti++)
	{
		strCheck=strPassword.substring(inti,inti+2);
		if(strCheck=="__")
		{
			alert("Two consecutive underscores are not allowed.");
			return false;
		}
	}
}


function captureKey(objText, chkCtrl, chkAlt, chkShift, objHidText){
	var strKey="";						
	
	if(chkCtrl.checked){			
		strKey="Ctrl";			
	}		
	if(chkAlt.checked){
		if(strKey==""){
			strKey="Alt";
		}else{
			strKey= strKey + "\+Alt";
		}
	}		
	if(chkShift.checked){
		if(strKey==""){
			strKey="Shift";
		}else{
			strKey= strKey + "\+Shift";
		}
	}		
		
	if(event.keyCode!=0){
			
		if(strKey==""){			
			strKey=String.fromCharCode(event.keyCode)
		}else{
				
			strKey= strKey + "\+" +String.fromCharCode(event.keyCode);
		}
	}else{
		if(strKey==""){			
			strKey=objText.value
		}else{
				
			strKey= strKey + "\+" + objText.value;
		}		
	}
	
		
	if(event.keyCode!=0){
		objText.value=String.fromCharCode(event.keyCode)		
	}
	objHidText.value=strKey;			
	event.keyCode=0;					
	return false;
}

function addOptions(objSelect,counts){
	var newOption;
	var strValue;
	for(intCount=1;intCount<=counts;intCount++){
		
		newOption=new Option();			
		if(intCount<=9){
			strValue = "0" + intCount.toString();
		}else{
			strValue = intCount.toString();
		}
		newOption.value= strValue;
		newOption.text= strValue;
		objSelect.options[objSelect.length]=newOption;		
			
	}
		
	objSelect.options[0].selected=true;
	objSelect.className="uname";

}
	
function selectOption(objSelect,selectVal){
	for(intCount=0;intCount<objSelect.length;intCount++){
			
		if(objSelect.options[intCount].value==selectVal){
				
			objSelect.options[intCount].selected=true;
		}
	}
		
}	
	
function fnSubmitRedeemCode(frmForm){
	var fname;
	var rcode;
	rcode=frmForm.txtRedeemCode.value;
	rcode=rcode.toUpperCase();
	rcode=rcode.substring(0,3);
	fname=document.URLUnencoded;
	if(frmForm.txtRedeemCode.value=="")	{
		alert("Please Enter Redeem Code.");
		frmForm.txtRedeemCode.focus();
		return;
	}
	if(frmForm.txtRedeemCode.value.length<10){
		alert("This is not a valid code.Please try again.");
		frmForm.txtRedeemCode.focus();
		return;
	}
	if(rcode!='GFT' && rcode!='SPC') {
		alert("This is not a valid code.Please try again.");
		frmForm.txtRedeemCode.focus();
		return;
	}
	frmForm.action="RedeemGift1.asp?fname="+fname;
	frmForm.submit();		
	
}

function selPeriodSelected(objSelect, strSelPeriod){
var intCount;

	for(intCount=0;intCount<objSelect.length;intCount++){
		
		if(objSelect.options[intCount].value==strSelPeriod){
				
			objSelect.options[intCount].selected=true;
			break;
		}
	}	
}

function changeSelctedPeriod(strValue, strRedirectPage){
	
	document.frmSearch.hidSelectedPeriod.value=strValue;
	document.frmSearch.hidRequestedPage.value=strRedirectPage;
	document.frmSearch.hidOptionPeriod.value='0';
	document.frmSearch.action="changeSelPeriod.asp";
	document.frmSearch.submit();
}

function setReportControl(strValue,strPeriod, strDelimeter){
var selPeriod, arrPeriod;
	
	selPeriod=strPeriod;
	
	if(strValue=='0'){
		cmbPeriodList.disabled=false;
		txtFromDay.disabled=true;
		txtFromMonth.disabled=true;
		txtFromYear.disabled=true;
		txtToDay.disabled=true;
		txtToMonth.disabled=true;
		txtToYear.disabled=true;
		optReportPeriod[0].checked=true;
	}else{
	
		
		cmbPeriodList.disabled=true;
		txtFromDay.disabled=false;		
		txtFromMonth.disabled=false;
		txtFromYear.disabled=false;
		txtToDay.disabled=false;
		txtToMonth.disabled=false;
		txtToYear.disabled=false;
		
		if(selPeriod.trim()!=''){
		
			arrPeriod=selPeriod.split(strDelimeter);
				
			txtFromDay.value=arrPeriod[0].substring(0,2);
			txtFromMonth.value=arrPeriod[0].substring(2,4);
			txtFromYear.value=arrPeriod[0].substring(6);
			txtToDay.value=arrPeriod[1].substring(0,2);
			txtToMonth.value=arrPeriod[1].substring(2,4);
			txtToYear.value=arrPeriod[1].substring(6);
		}		
		optReportPeriod[1].checked=true;
		
	}
	
}

function fnSubmitPeriod(strRedirectPage, strDelimeter){
var strTo, strFrom, strValue;
	
	if(optReportPeriod[0].checked){
		return;
	}
	
	var strFromDay, strFromMonth, strFromYear;
	var strToDay, strToMonth, strToYear;
	
	strFromDay = parseInt(txtFromDay.value);  		
	strFromMonth = parseInt(txtFromMonth.value);
	strFromYear = '20' + txtFromYear.value
	
	strToDay = parseInt(txtToDay.value);
	strToMonth =  parseInt(txtToMonth.value);
	strToYear = '20' + txtToYear.value
	
	if(!validate(strFromDay, strFromMonth, strFromYear)){
		alert("Please enter valid FROM date!");
		txtFromMonth.focus();
		return;
	}
	
	if(!validate(strToDay, strToMonth, strToYear)){
		alert("Please enter valid TO date!");
		txtToMonth.focus();
		return;
	}
		
	if(parseInt(strFromDay)<10){
		strFromDay="0" + parseInt(strFromDay);		
	}
	
	if(parseInt(strFromMonth)<10){
		strFromMonth="0" + parseInt(strFromMonth);		
	}
	
	if(parseInt(strToDay)<10){
		strToDay="0" + parseInt(strToDay);		
	}
	
	if(parseInt(strToMonth)<10){
		strToMonth="0" + parseInt(strToMonth);		
	}
	
	strFrom= strFromDay + strFromMonth + strFromYear
	strTo= strToDay + strToMonth + strToYear
	
	date1 = new Date(strFromYear + '/' + strFromMonth + '/' + strFromDay);
	date2 = new Date(strToYear + '/' + strToMonth + '/' + strToDay);
	
	if(date1>date2){
		alert("From date should be less than To date!")
		return;
	}
	strValue=strFrom + strDelimeter + strTo	
	document.frmSearch.hidSelectedPeriod.value=strValue;
	document.frmSearch.hidRequestedPage.value=strRedirectPage;
	document.frmSearch.hidOptionPeriod.value='1';
	document.frmSearch.action="changeSelPeriod.asp";
	document.frmSearch.submit();		
		
}
function validate(dd,mm,yy)
{
   
   var chk    = 0;
   var maxDay = 0;
   
   var _dd=parseInt(dd);
   var _mm=parseInt(mm);
   var _yy=parseInt(yy);

   
   // calling function to get maximum day for this month
   maxDay = max_day(mm, yy);  
   if(dd!=_dd || mm!=_mm || yy!=_yy)   { chk = 1;}
   else if((dd <= 0) || (dd > maxDay)) { chk = 1;}
   else if((mm <= 0) || (mm > 12))     { chk = 1;}
   else if((yy <= 0))                  { chk = 1;} 

   if(chk) { return false; }
   else    { return true; }
   
}

// function for calculating maximum day 
function max_day(mn, yr)
{
  var mDay;
  if((mn == 4) || (mn == 6) || (mn == 9) || (mn == 11))
  { 
    mDay = 30;
  }
  else if(mn == 2)
  {
    //calling leap year function 
    mDay = isLeapYear(yr) ? 29 : 28;    
  }
  else
  {
    mDay = 31;
  }
  return mDay; 
}

// function to check leap year
function isLeapYear(yr)
{
  if      (yr % 4 != 0)   return false;
  else if (yr % 400 == 0) return true;
  else if (yr % 100 == 0) return false;
  else                    return true;
}
