var popUpWin=0;
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+.";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
function verifyIP (IPvalue) {
	errorString = "";
	theName = "IPaddress";
	
	var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	var ipArray = IPvalue.match(ipPattern);
	
	if (IPvalue == "0.0.0.0")
	errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
	else if (IPvalue == "255.255.255.255")
	errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
	if (ipArray == null)
	errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
	else {
	for (i = 0; i < 4; i++) {
	thisSegment = ipArray[i];
	if (thisSegment > 255) {
	errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
	i = 4;
	}
	if ((i == 0) && (thisSegment > 255)) {
	errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
	i = 4;
		  }
	   }
	}
	extensionLength = 3;
	if (errorString == "")
	return true;
	else
	return false;
}
function input_filterAmt (str, dec, bNeg)
{ // auto-correct input - force numeric data based on params.
if (trim(str)=="") return "";
if (dec==1) MyNo=10;
if (dec==2) MyNo=100;
if (dec==3) MyNo=1000;
if (dec==4) MyNo=10000;
 var cDec = '.'; // decimal point symbol
 var bDec = 0; var val = "";
 var strf = ""; var neg = ""; var i = 0;
 if (str == "") return; Math.round (parseFloat ("0")*MyNo)/MyNo;
 if (bNeg && str.charAt (i) == '-') { neg = '-'; i++; }

 for (i; i < str.length; i++)
 {
  val = str.charAt (i);
  if (val == cDec)
  {
   if (!bDec) { strf += val; bDec = 1; }
  }
  else if (val >= '0' && val <= '9')
   strf += val;
 }
 strf = (strf == "" ? 0 : neg + strf);
 MyValue=String( Math.round (parseFloat (strf)*MyNo)/MyNo);
 if(MyValue.charAt(MyValue.length-2)==".") return MyValue+"0"; else return MyValue;
} 

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function doTooltip(e, msg) {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.show(e, msg);
}

function hideTip() {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.hide();
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function validateZIP(field) {
var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
var hyphencount = 0;

//if (field.length!=5 && field.length!=10) {
//alert("Please enter your 5 digit or 5 digit+4 zip code.");
//return false;
//}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
//alert("Invalid characters in your zip code.  Please try again.");
return false;
}
//if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
//alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
//return false;
//   }
}
return true;
}

function validateTitle(field) {
var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&$-#.' ";

for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (valid.indexOf(temp) == "-1") {
//alert("Invalid characters in your zip code.  Please try again.");
return false;
}

}
return true;
}

function validURLExtra(field) {
if(field.indexOf("'")>0 || field.indexOf('"')>0) return false; else return true;
}

function validatePassword(field) {
var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";

for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (valid.indexOf(temp) == "-1") {
//alert("Invalid characters in your zip code.  Please try again.");
return false;
}

}
return true;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh==32))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

function alphanumeric2(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) )
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}
function alphanumeric3(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh==95))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}
function alpha(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh==32))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}
function popup(URLStr, left, top, width, height, scrollflag, toolbar, resize)
{
  if (scrollflag == null) {
	  scrollflag = 'no';
  }
  
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar='+toolbar+',location=no,directories=no,status=no,menubar=no,scrollbars='+scrollflag+',resizable='+resize+',copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

// START OF functions for venueevent.php and showevent.php to control Iframe loading.

	function frmOptions_onSubmit()
	{		
		with(document.frmOptions)
		{
			//if (trim(txtStartDate.value)=="" && cmbOption.value=="range"){
			//	alert("Please select Start Date."); txtStartDate.focus(); return false;
			//}
			//return true;
			submit();
		}
	}
	
	function ProcessEvent(QS, thedate)
	{
		with(document.frmEvent)
		{
			FrameName=parent.window.document.getElementById("iFrameEventDetail");
			FrameName.src="eventdetail.php?"+QS+"&thedate="+thedate;						
			parent.document.getElementById('detailsheader').value="ABOUT THIS EVENT";	
		}
	}
	function SubmitSortingForm(Field,SortType)
	{
		with(frmOptions)
		{
			hdnSortField.value=Field;
			hdnSortType.value=SortType;
			hdnCalendarDate.value="";
			submit();
		}
	}	
	
	function Submit_click(UserID,Action)
	{
		with(document.form1)
		{
			if(Action==1)
				hdnMode.value="edit";
			else if(Action==2)
			{
				if(!confirm("Are you sure to delete the Item permanently ?")) return;
				hdnMode.value="delete";
			}
			else if(Action==3)
			{
				hdnMode.value="view";
			}
			else if(Action==0)
			{
				hdnMode.value="add";
			}			
			hdnItemID.value=UserID
			submit();
		}
	}
	
// END OF functions for venueevent.php and showevent.php to control Iframe loading.

function showflash(object) {
if (document.layers && document.layers[object] != null)
		document.layers[object].visibility = 'visible';
	else if (document.all) {
		document.all[object].style.visibility = 'visible';
	}
	else
		document.getElementById(object).style.visibility = 'visible';
}

function hideflash(object) {
	if (document.layers && document.layers[object] != null)
		document.layers[object].visibility = 'hidden';
	else if (document.all)
		 document.all[object].style.visibility = 'hidden';
	else
		document.getElementById(object).style.visibility = 'hidden';
}

function isValidURL(str){		
	//var reg1str = "^http:\/\/www.";
	var reg1str = "^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$";
	var reg1 = new RegExp(reg1str);
	if (reg1.test(str)) { if(validURLExtra(str)) return true; else return false; }
	else return false;
	

}

function isValidEmail(str) {
	var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)| ";
	var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
	var reg1 = new RegExp(reg1str);
	var reg2 = new RegExp(reg2str);
	if (!reg1.test(str) && reg2.test(str)) return true;

	return false;
}

function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}

function ShowHideObject(ObjectID)
{
	if (!document.getElementById) return
	with(document.getElementById(ObjectID))
	{
		if (style.display=="")
			style.display="none"
		else
			style.display=""
	}		
}

// Date Chk Function //

var tokPat=new RegExp("^month_strict|month|Month|MONTH|yyyy|YYYY|mins|MINS|mon_strict|ampm|AMPM|mon|Mon|MON|min|MIN|dd|DD|mm|MM|yy|YY|hh|HH|ss|SS|m|M|d|D|y|Y|h|H|s|S");
var lowerMonArr={jan:1, feb:2, mar:3, apr:4, may:5, jun:6, jul:7, aug:8, sep:9, oct:10, nov:11, dec:12}
var monPatArr=new Array();
monPatArr['mon_strict']=new RegExp(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/);
monPatArr['Mon']=new RegExp(/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/);
monPatArr['MON']=new RegExp(/JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC/);
monPatArr['mon']=new RegExp("jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",'i');
var monthPatArr=new Array();
monthPatArr['month']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/i);
monthPatArr['Month']=new RegExp(/^January|February|March|April|May|June|July|August|September|October|November|December/);
monthPatArr['MONTH']=new RegExp(/^JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER/);
monthPatArr['month_strict']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/);
var cutoffYear=50;
function FormatToken (token, type) {
	this.token=token;
	this.type=type;
}
function parseFormatString (formatStr) {
	var tokArr=new Array;
	var tokInd=0;
	var strInd=0;
	var foundTok=0;
    while (strInd < formatStr.length) {
		if (formatStr.charAt(strInd)=="%" && (matchArray=formatStr.substr(strInd+1).match(tokPat)) != null) {
			strInd+=matchArray[0].length+1;
			tokArr[tokInd++]=new FormatToken(matchArray[0],"symbolic");
		}else{
			if (tokInd>0 && tokArr[tokInd-1].type=="literal") {
				tokArr[tokInd-1].token+=formatStr.charAt(strInd++);
			}else {
				tokArr[tokInd++]=new FormatToken(formatStr.charAt(strInd++), "literal");
			}
		}
	}
	return tokArr;
}


function buildDate(dateStr,formatStr) {
	var tokArr=parseFormatString(formatStr);
	var strInd=0;
	var tokInd=0;
	var intMonth;
	var intDay;
	var intYear;
	var intHour;
	var intMin;
	var intSec;
	var ampm="";
	var strOffset;
	var curdate=new Date();
	intMonth=curdate.getMonth()+1;
	intDay=curdate.getDate();
	intYear=curdate.getFullYear();
	intHour=0;
	intMin=0;
	intSec=0;
	while (strInd < dateStr.length && tokInd < tokArr.length) {
		if (tokArr[tokInd].type=="literal") {
			if (dateStr.indexOf(tokArr[tokInd].token,strInd)==strInd) {
				strInd+=tokArr[tokInd++].token.length;
				continue;
			}else{
				return "\"" + dateStr + "\" does not conform to the expected format: " + formatStr;
			}
		}
		switch (tokArr[tokInd].token) {
			case 'm':
			case 'M':
			case 'd':
			case 'D':
			case 'h':
			case 'H':
			case 'min':
			case 'MIN':
			case 's':
			case 'S':
				curChar=dateStr.charAt(strInd);
				nextChar=dateStr.charAt(strInd+1);
				matchArr=dateStr.substr(strInd).match(/^\d{1,2}/);
				if (matchArr==null) {
					switch (tokArr[tokInd].token.toLowerCase()) {
						case 'd': var unit="day"; break;
						case 'm': var unit="month"; break;
						case 'h': var unit="hour"; break;
						case 'min': var unit="minute"; break;
						case 's': var unit="second"; break;
					}
					return "Bad " + unit + " \"" + curChar + "\" or \"" + curChar +
					nextChar + "\".";
				}
				strOffset=matchArr[0].length;
				switch (tokArr[tokInd].token.toLowerCase()) {
					case 'd': intDay=parseInt(matchArr[0],10); break;
					case 'm': intMonth=parseInt(matchArr[0],10); break;
					case 'h': intHour=parseInt(matchArr[0],10); break;
					case 'min': intMin=parseInt(matchArr[0],10); break;
					case 's': intSec=parseInt(matchArr[0],10); break;
				}
				break;
			case 'mm':
			case 'MM':
			case 'dd':
			case 'DD':
			case 'hh':
			case 'HH':
			case 'mins':
			case 'MINS':
			case 'ss':
			case 'SS':
				strOffset=2;
				matchArr=dateStr.substr(strInd).match(/^\d{2}/);
				if (matchArr==null) {
					switch (tokArr[tokInd].token.toLowerCase()) {
						case 'dd': var unit="day"; break;
						case 'mm': var unit="month"; break;
						case 'hh': var unit="hour"; break;
						case 'mins': var unit="minute"; break;
						case 'ss': var unit="second"; break;
					}
					return "Bad " + unit + " \"" + dateStr.substr(strInd,2) + "\".";
				}
				switch (tokArr[tokInd].token.toLowerCase()) {
					case 'dd': intDay=parseInt(matchArr[0],10); break;
					case 'mm': intMonth=parseInt(matchArr[0],10); break;
					case 'hh': intHour=parseInt(matchArr[0],10); break;
					case 'mins': intMin=parseInt(matchArr[0],10); break;
					case 'ss': intSec=parseInt(matchArr[0],10); break;
				}
				break;
			case 'y':
			case 'Y':
				if (dateStr.substr(strInd,4).search(/\d{4}/) != -1) {
					intYear=parseInt(dateStr.substr(strInd,4),10);
					strOffset=4;
				}else{
					if (dateStr.substr(strInd,2).search(/\d{2}/) != -1) {
						intYear=parseInt(dateStr.substr(strInd,2),10);
						if (intYear>=cutoffYear) {
							intYear+=1900;
						}else{
							intYear+=2000;
						}
						strOffset=2;
					}else {
						return "Bad year \"" + dateStr.substr(strInd,2) + "\". Must be two or four digits.";
					}
				}
				break;
			case 'yy':
			case 'YY':
				if (dateStr.substr(strInd,2).search(/\d{2}/) != -1) {
					intYear=parseInt(dateStr.substr(strInd,2),10);
					if (intYear>=cutoffYear) {
						intYear+=1900;
					}else {
						intYear+=2000;
					}
					strOffset=2;
				}else{
					return "Bad year \"" + dateStr.substr(strInd,2) + "\". Must be two digits.";
				}
				break;
			case 'yyyy':
			case 'YYYY':
				if (dateStr.substr(strInd,4).search(/\d{4}/) != -1) {
					intYear=parseInt(dateStr.substr(strInd,4),10);
					strOffset=4;
				}else{
					return "Bad year \"" + dateStr.substr(strInd,4) + "\". Must be four digits.";
				}
				break;
			case 'mon':
			case 'Mon':
			case 'MON':
			case 'mon_strict':
				monPat=monPatArr[tokArr[tokInd].token];
				if (dateStr.substr(strInd,3).search(monPat) != -1) {
					intMonth=lowerMonArr[dateStr.substr(strInd,3).toLowerCase()];
				}else{
					switch (tokArr[tokInd].token) {
						case 'mon_strict': caseStat="lower-case"; break;
						case 'Mon': caseStat="mixed-case"; break;
						case 'MON': caseStat="upper-case"; break;
						case 'mon': caseStat="between Jan and Dec"; break;
					}
					return "Bad month \"" + dateStr.substr(strInd,3) + "\". Must be " + caseStat + ".";
				}
				strOffset=3;
				break;
			case 'month':
			case 'Month':
			case 'MONTH':
			case 'month_strict':
				monPat=monthPatArr[tokArr[tokInd].token];
				matchArray=dateStr.substr(strInd).match(monPat);
				if (matchArray==null) {
					return "Can't find a month beginning at \"" + dateStr.substr(strInd) + "\".";
				}
				intMonth=lowerMonArr[matchArray[0].substr(0,3).toLowerCase()];
				strOffset=matchArray[0].length;
				break;
			case 'ampm':
			case 'AMPM':
				matchArr=dateStr.substr(strInd).match(/^(am|pm|AM|PM|a\.m\.|p\.m\.|A\.M\.|P\.M\.)/);
				if (matchArr==null) {
					return "Missing am/pm designation.";
				}
				if (matchArr[0].substr(0,1).toLowerCase() == "a") {
					ampm = "am";
				}else{
					ampm = "pm";
				}
				strOffset = matchArr[0].length;
				break;
		}
		strInd += strOffset;
		tokInd++;
	}
	if (tokInd != tokArr.length || strInd != dateStr.length) {
		return "\"" + dateStr + "\" is either missing desired information or has more information than the expected format: " + formatStr;
	}
	if (intMonth < 1 || intMonth > 12) {
		return "Month must be between 1 and 12.";
	}
	if (intDay < 1 || intDay > 31) {
		return "Day must be between 1 and 31.";
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && intDay == 31) {
		return "Month "+intMonth+" doesn't have 31 days!";
	}
	if (intMonth == 2) {
		var isleap=(intYear%4==0 && (intYear%100!=0 || intYear%400==0));
		if (intDay > 29 || (intDay == 29 && !isleap)) {
			return "February " + intYear + " doesn't have " + intDay + " days!";
		  }
	}
	if (ampm == "") {
		if (intHour < 0 || intHour > 23) {
			return "Hour must be between 0 and 23 for military time.";
		}
	}else {
		if (intHour < 1|| intHour > 12) {
			return "Hour must be between 1 and 12 for standard time.";
		}
	}
	if (ampm=="am" && intHour==12) {
		intHour=0;
	}
	if (ampm=="pm" && intHour < 12) {
		intHour += 12;
	}
	if (intMin < 0 || intMin > 59) {
		return "Minute must be between 0 and 59.";
	}
	if (intSec < 0 || intSec > 59) {
		return "Second must be between 0 and 59.";
	}
	return new Date(intYear,intMonth-1,intDay,intHour,intMin,intSec);
}
function dateCheck(dateStr,formatStr) {
	var myObj = buildDate(dateStr,formatStr);
	if (typeof myObj == "object") {
		return true;
	}else {
		return false;
   }
}

// Main Site Javascript
	var req;	
	function callback2() {
		if (req.readyState == 4) 
		{
			if (req.status == 200) 
			{
				var message = req.responseXML.getElementsByTagName("message")[0];  								
				retvalue=message.childNodes[0].nodeValue;
				if(retvalue=='invalid')
				{
					alert("Invalid login details entered.");
					document.getElementById('Login').focus();
				}				
				else if(retvalue=='inactive')
				{	
					alert("Login is currently in-active,\n\rPlease active your account through the link which we have sent to your email.");
					document.getElementById('Login').focus();
				}
				else if(retvalue=='banned')
				{	
					alert("Login is currently Banned.");
					document.getElementById('Login').focus();
				}
				else { 
					with (document.frmSignin)
					{			
						submit();
					}
				}
			}
		}
	}
	
	function ValidateLogin()
	{
		Frm=this.document.frmFeedback;		
		var url = "managelogin.php?login=" + escape(document.getElementById('Login').value)+"&pass=" + escape(document.getElementById('Password').value); 

			if (window.XMLHttpRequest) {
				req = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			req.open("GET", url, true);
			req.onreadystatechange = callback2;						
			req.send(null);			
	}
	
	function frmSignin_onSubmit()
	{
		with(document.frmSignin)
		{
			if (trim(txtLogin.value)==""){
				alert("Please enter your login name."); document.getElementById('Login').focus(); return false;
			}
			else if (txtPassword.value==""){
				alert("Please enter valid password."); document.getElementById('Password').focus(); return false;
			}
			return true;
		}
	}
	
	function setValues()
	{
		with (document.frmSignin)
		{			
			txtLogin.value=document.getElementById('Login').value;
			txtPassword.value=document.getElementById('Password').value;			
			if (frmSignin_onSubmit()) { ValidateLogin(); }
		}
	}	
	
	
	function SignUp()
	{
		with(document.frmSignUp)
		{
			submit();
		}
	}	
	function  doPFKey(e) {	  		
	  if(e.keyCode==13)	{setValues(); }
	}
//---------------------------------------------

//--------------------Register Vendor Java Code
	function EditMyAccount(UserID)
	{
		with(document.frmEditUser)
		{
			hdnMode.value="edit";
			hdnUserID.value=UserID;
			submit();
		}
	}	
	
	function IsValidVendorUser()
	{
		Frm=this.document.form1;
		Err="";
		Obj='';
		if (Frm.txtFName.value.length<1 || alpha(Frm.txtFName.value)==false)
		{
			Err=Err+"Please type a valid Name. Your entry should\navoid special characters and numbers. \n\r";
			if(Obj=='')	Obj=Frm.txtFName;
		}				
		if (Frm.txtEmail.value=="" || !isValidEmail(Frm.txtEmail.value) ){				
			Err=Err+"Please enter valid Email Address .\n\r";
			if(Obj=='') Obj=Frm.txtEmail;
		}
		if (Frm.txtEmailB.value=="" || !isValidEmail(Frm.txtEmailB.value) ){				
			Err=Err+"Please enter valid Retype Email Address .\n\r";
			if(Obj=='') Obj=Frm.txtEmailB;
		}
		if(Frm.hdnMode.value=="add")
		{
			if (Frm.txtEmail.value != Frm.txtEmailB.value) {
				Err=Err+"your email addresses do not match. Please check again .\n\r";
				if(Obj=='') Obj=Frm.txtEmail;
			}		
		}
		if (Frm.cmbUserType.value=="Vendor" && Frm.txtBusiness.value.length<1)
		{
			Err=Err+"Please enter a valid Business Name .\n\r";
			if(Obj=='') Obj=Frm.txtBusiness;
		}			
		if (Frm.cmbUserType.value=="Vendor" && Frm.txtPhone.value!='' && checkInternationalPhone(Frm.txtPhone.value)==false)
		{
			Err=Err+"Please enter a valid Phone .\n\r";
			if(Obj=='') Obj=Frm.txtPhone;
		}
		if (Frm.cmbUserType.value=="Vendor" && Frm.txtZip.value!='' && validateZIP(Frm.txtZip.value)==false)
		{
			Err=Err+"Please enter valid Zip. - is the only special character allowed.\n\r";
			if(Obj=='') Obj=Frm.txtZip;
		}	
		if (Frm.cmbUserType.value=="Vendor" && Frm.txtFax.value!='' && checkInternationalPhone(Frm.txtFax.value)==false)
		{
			Err=Err+"Please enter a valid Fax .\n\r";
			if(Obj=='') Obj=Frm.txtFax;
		}	
		if (Frm.cmbUserType.value=="Vendor" && Frm.txtMobilePhone.value!='' && checkInternationalPhone(Frm.txtMobilePhone.value)==false)
		{
			Err=Err+"Please enter a valid Mobile Phone .\n\r";
			if(Obj=='') Obj=Frm.txtMobilePhone;
		}
		if (Frm.txtWebSite.value!='' && isValidURL(Frm.txtWebSite.value)==false)
		{
			Err=Err+"Please enter a valid Website .\n\r";
			if(Obj=='') Obj=Frm.txtWebSite;
		}
		if (Frm.txtUName.value.length<1 || alphanumeric3(Frm.txtUName.value)==false)
		{
			Err=Err+"Please type valid Username using only\nalphabetical, underscore and numeric characters with no spaces.\n\r";
			if(Obj=='') Obj=Frm.txtUName;
		}		
		if (Frm.txtPass1.value.length<1)
		{
			Err=Err+"Please type valid Password .\n\r";
			if(Obj=='') Obj=Frm.txtPass1;
		}
		if (Frm.txtPass2.value.length<1)
		{
			Err=Err+"Please retype password in second password field .\n\r";
			if(Obj=='') Obj=Frm.txtPass2;
		}
		if (validatePassword(Frm.txtPass1.value)==false || validatePassword(Frm.txtPass2.value)==false){
			Err=Err+"Please retype password.\n The only special characters allowed are \"!@#$%^&*\", Spaces are also not allowed.\n\r";
			if(Obj=='') Obj=Frm.txtPass1;
		}
		if (Frm.txtPass1.value!=Frm.txtPass2.value)
		{
			Err=Err+"Typed Password fields do not match .\n\r";
			if(Obj=='') Obj=Frm.txtPass2;
		}	
		if(Frm.hdnMode.value=="add")
		{
			if (Frm.keystring.value.length<1)
			{
				Err=Err+"Please type image string to validate .\n\r";
				if(Obj=='') Obj=Frm.keystring;
			}	
		}
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	else return true;
		
	}
	function ManageControlRegister()
	{
		if(document.form1.cmbUserType!=null)
		{
			if(document.form1.cmbUserType.value=="Vendor") Action=1; else Action=0;
			if(document.getElementById("tblCode")!=null)
			{
				if (Action==0)  document.getElementById("tblCode").style.display='none';
				 else document.getElementById("tblCode").style.display='';
			}
		}
	}
	function ManageControlComments(Action)
	{
		if(document.getElementById("tblComments")!=null)
		{
			if (document.getElementById("tblComments").style.display=='')  document.getElementById("tblComments").style.display='none';
			 else document.getElementById("tblComments").style.display='';
		}
	}
	function ManageControlDate(Action)
	{
		if(document.form1.chkLimited.value=="1") Action=1; else Action=0;
		if(document.getElementById("tblDate")!=null)
		{
			if (Action==0) document.getElementById("tblDate").style.display='none';
			 else document.getElementById("tblDate").style.display='';
		}
	}
//--------------------------------------------
//-------------------Items Javascript
	function ManageControl()
	{
		if(document.form1.cmbItemType!=null)
		{
			if(document.form1.cmbItemType.value=="Coupon") Action=1; else Action=0;
			if(document.getElementById("tblCode")!=null)
			{
				if (Action==0)  document.getElementById("tblCode").style.display='none';
				 else document.getElementById("tblCode").style.display='';
			}
			if(document.form1.cmbItemType.value=="Promotion") Action=1; else Action=0;
			if(document.getElementById("tblSavings")!=null)
			{
				if (Action==0)  document.getElementById("tblSavings").style.display='none';
				 else document.getElementById("tblSavings").style.display='';
			}
		}
	}
	function ManageControlMain(CurType)
	{		
		if(CurType=="Vendor") { Action=1; }
		else if(CurType=="Friend")  { Action=0; }
		else { Action=2; }
		document.form1.cmbUserType.value=CurType;
		if(document.getElementById("tblAllTable")!=null)
		{
			if (Action==0) 
			{
				document.getElementById("tblAllTable").style.display='';
				document.getElementById("tblCode").style.display='none';				
				document.getElementById("tblDesc1").style.display='';
				document.getElementById("tblDesc2").style.display='none';
			}
			 else if(Action==1)
			 {
			 	document.getElementById("tblAllTable").style.display='';
				document.getElementById("tblCode").style.display='';
				document.getElementById("tblDesc1").style.display='none';
				document.getElementById("tblDesc2").style.display='';
			 }
			 else if(Action==2)
			 {
			 	document.getElementById("tblAllTable").style.display='none';
				document.getElementById("tblCode").style.display='none';
			 }
		}		
	}
	function RemoveItem(ObjSrc, ObjTarget)
	{
		Frm=document.form1;		
		src = eval( 'document.form1.' + ObjSrc );
		target = eval( 'document.form1.' + ObjTarget );
		if (src.value=='') {alert("Please select valid Tag."); return;}
		var x=new Option();
		x.value=src.value;
		x.text=src.options[src.selectedIndex].text;
		target.options[target.options.length]=x;
		src.options[src.selectedIndex]=null;		
	}	
	function MoveItem(ObjSrc, ObjTarget)
	{		 
		Frm=document.form1;		
		src = eval( 'document.form1.' + ObjSrc );
		target = eval( 'document.form1.' + ObjTarget );		
		if (src.value=='') {alert("Please select valid Tag."); return;}		
		for(k=0;k<=target.options.length-1;k++)
		{
			if(target.options[k].value==src.value) {alert("Tag already found in the List.");return;}
		}				
			var x=new Option();
			x.value=src.value;
			x.text=src.options[src.selectedIndex].text;
			target.options[target.options.length]=x;
			src.options[src.selectedIndex]=null;				
	}
	function SetList()
	{
		with (document.form1)
		{
			TempVar='';
			for (var i=0; i<lstSelTags.options.length; i++) 
			{
				TempVar=TempVar+'#'+lstSelTags.options[i].value;
			}
			hdnList.value=TempVar;
		}		
	}
	function Delete_Items()
	{
		with(document.frmManageList)	
		{
			if(!confirm("Are you sure to delete the Item(s) permanently ?")) return;	
			submit();
		}
	}
	function IsValidItemData()
	{
		Frm=this.document.form1;
		Err="";		
		Obj='';
		if (Frm.cmbItemType.value.length<1)
		{
			Err=Err+"Please select valid Deal Type .\n\r";
			if(Obj=='') Obj=Frm.txtTitle;
		}
		/*if (Frm.cmbMetro.value.length<1)
		{
			Err=Err+"Please select valid Metro Area .\n\r";
			if(Obj=='') Obj=Frm.txtTitle;
		}*/
		if (Frm.txtTitle.value.length<1 || validateTitle(Frm.txtTitle.value)==false)
		{
			Err=Err+"Please type valid Title.  The only special characters\nallowed are ', &, $, -, #, and .\n\r";
			if(Obj=='') Obj=Frm.txtTitle;
		}
		if (Frm.txtDetails.value.length<1)
		{
			Err=Err+"Please type valid Details .\n\r";
			if(Obj=='') Obj=Frm.txtDetails;
		}
		/*if (Frm.txtGet.value.length<1)
		{
			Err=Err+"Please type how to get Deal Details .\n\r";
			if(Obj=='') Obj=Frm.txtGet;
		}*/
		if (Frm.txtTags.value.length<1 || alphanumeric(Frm.txtTags.value)==false)
		{
			Err=Err+"Please enter valid Tags using only\nalphabetical and numeric characters.\n\r";
			if(Obj=='') Obj=Frm.txtTags;
		}
		
		if (Frm.chkLimited.value=='1' && Frm.txtExpireDate.value.length<1)
		{
			Err=Err+"Please type valid Expire Date .\n\r";
			if(Obj=='') Obj=Frm.txtExpireDate;
		}		

		d1 = new Date(Frm.txtExpireDate.value);
		d2 = new Date();
		d2.setDate(d2.getDate()-1)
		
		if (Frm.chkLimited.value=='1' && d1<d2)
		{
			Err=Err+"Expire Date can't be less than creation date.\n\r";
			if(Obj=='') Obj=Frm.txtExpireDate;
		}
		if (Frm.txtPrice.value.length>=1 && isNaN(Frm.txtPrice.value))
		{
			Err=Err+"Please type valid Price .\n\r";
			if(Obj=='') Obj=Frm.txtPrice;
		}
		if (Frm.cmbItemType.value=="Promotion" && Frm.txtSavings.value.length>=1 && isNaN(Frm.txtSavings.value))
		{
			Err=Err+"Please type valid Savings .\n\r";
			if(Obj=='') Obj=Frm.txtSavings;
		}
		/*if (Frm.txtPrice.value.length>=1 && Frm.txtSavings.value.length>=1 && parseFloat(Frm.txtSavings.value)>parseFloat(Frm.txtPrice.value))
		{
			Err=Err+"Please type savings amount less than actual price .\n\r";
			if(Obj=='') Obj=Frm.txtSavings;
		}*/
		if (Frm.txtPrice.value.length==0 && Frm.txtSavings.value.length>=1 )
		{
			Err=Err+"Please type actual price first to mention savings.\n\r";
			if(Obj=='') Obj=Frm.txtPrice;
		}
		
		if (Frm.txtWebsite.value!='' && isValidURL(Frm.txtWebsite.value)==false)
		{
			Err=Err+"Please enter a valid Website .\n\r";
			if(Obj=='') Obj=Frm.txtWebsite;
		}
		if(Frm.hdnMode.value=="add")
		{
			if (Frm.keystring.value.length<1)
			{
				Err=Err+"Please type image string to validate .\n\r";
				if(Obj=='') Obj=Frm.keystring;
			}	
		}
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	else return true;
	}
//---------------------------------------------
//--------------------Recommend Someone	
function IsValidRecData()
	{
		Frm=this.document.form1;
		Err="";		
		Obj='';
		if (Frm.txtName.value.length<1 || alpha(Frm.txtName.value)==false)
		{
			Err=Err+"Please enter valid Name .\n\r";
			if(Obj=='') Obj=Frm.txtName;
		}
		if (Frm.txtEmail.value=="" || !isValidEmail(Frm.txtEmail.value) )
		{
			Err=Err+"Please type valid Email .\n\r";
			if(Obj=='') Obj=Frm.txtEmail;
		}
		if (Frm.txtAddresses.value.length<1)
		{
			Err=Err+"Please type valid Recipient Email Address .\n\r";
			if(Obj=='') Obj=Frm.txtAddresses;
		}
		if (Frm.txtAddresses.value.length>=1)
		{
			A=Frm.txtAddresses.value.split(",");
			for(i=0;i<=A.length-1;i++)
			{
				if(!isValidEmail(trim(A[i])))
				{
					Err=Err+"Please type valid Recipient Email Address .\n\r";
					if(Obj=='') Obj=Frm.txtAddresses;
					break;
				}				
			}
		}		
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	else return true;
	}
//------------------------------------
//-------------------------Search Tag
	function SearchTag(itemid)
	{
		with(document.MyTagForm)	
		{
			txtTag.value=itemid;
			submit();
		}
	}
	function ResetDates()
	{
		with(document.form2)
		{			
			txtTag.value='';
			cmbPromoType.value='All';
			txtTitle.value='';
			txtUName.value='';
			txtCoupenCode.value='';
			txtCreationDate.value='';
			txtCreationDate2.value='';
			txtExpireDate.value='';
			txtExpireDate2.value='';			
			txtTitle.focus();
		}
	}
//-----------------------------
//------------------------------------
//-------------------------Show Profile
	function ShowProfile(UName)
	{
		with(document.MyProfileForm)	
		{
			txtUName.value=UName;
			submit();
		}
	}
//-----------------------------
function highlight(div){
  div.className="folderButton";
}
function myhighlight(div){	
  if(div=='Reg1')
  {
  	document.getElementById(div).className="folderButton";
	document.getElementById('Reg2').className="folders";
  }
  else
  {
	  	document.getElementById(div).className="folderButton";
		document.getElementById('Reg1').className="folders";
	  }
}
function taghighlight(div){	  
  	document.getElementById(div).className="folderButton";
}
function unhighlight(div){
  div.className="folders";
}
//--------------------Coupon Popup
	function Popup(UniqID)
	{		
		w=600;
		h=600;
		LeftPos=(screen.width)?(screen.width-w)/2:100;
		TopPos=(screen.height)?(screen.height-h)/2:100;					
		RetValue=window.open('choosetemplete.php?uniqid='+UniqID,"newWindow",'center=yes,width='+ w +',height='+ h +',scrollbars=yes,status:no,left='+LeftPos+',top='+TopPos);			
	}
	function PopupAdmin(UniqID)
	{		
		w=600;
		h=600;
		LeftPos=(screen.width)?(screen.width-w)/2:100;
		TopPos=(screen.height)?(screen.height-h)/2:100;					
		RetValue=window.open('../choosetemplete.php?uniqid='+UniqID,"newWindow",'center=yes,width='+ w +',height='+ h +',scrollbars=yes,status:no,left='+LeftPos+',top='+TopPos);			
	}
	function Popup2(ItemID)
	{		
		w=600;
		h=600;
		LeftPos=(screen.width)?(screen.width-w)/2:100;
		TopPos=(screen.height)?(screen.height-h)/2:100;					
		RetValue=window.open('showcoupon.php?itemid='+ItemID,"newWindow",'center=yes,width='+ w +',height='+ h +',scrollbars=yes,status:no,left='+LeftPos+',top='+TopPos);			
	}
	function Popup3(ItemID)
	{		
		w=600;
		h=600;
		LeftPos=(screen.width)?(screen.width-w)/2:100;
		TopPos=(screen.height)?(screen.height-h)/2:100;					
		RetValue=window.open('showimage.php?itemid='+ItemID,"newWindow",'center=yes,width='+ w +',height='+ h +',scrollbars=yes,status:no,left='+LeftPos+',top='+TopPos);			
	}
	function Popup2Admin(ItemID)
	{		
		w=600;
		h=600;
		LeftPos=(screen.width)?(screen.width-w)/2:100;
		TopPos=(screen.height)?(screen.height-h)/2:100;					
		RetValue=window.open('../showcoupon.php?itemid='+ItemID,"newWindow",'center=yes,width='+ w +',height='+ h +',scrollbars=yes,status:no,left='+LeftPos+',top='+TopPos);			
	}
//--------------------------------
function login(showhide){
    if(showhide == "show"){
		HideObjects();
		HideDropdowns();
        document.getElementById('popupbox').style.visibility="visible"; /* If the function is called with the variable 'show', show the login box */
		document.getElementById('Login').focus();
    }else if(showhide == "hide"){
		ShowDropdowns();
        document.getElementById('popupbox').style.visibility="hidden"; /* If the function is called with the variable 'hide', hide the login box */

    }
  }
  
 function setloading(showhide){
    if(showhide == "show"){
		HideObjects();
		HideDropdowns();
        document.getElementById('loadingpopupbox').style.visibility="visible"; /* If the function is called with the variable 'show', show the login box */
    }else if(showhide == "hide"){
		ShowDropdowns();
        document.getElementById('loadingpopupbox').style.visibility="hidden"; /* If the function is called with the variable 'hide', hide the login box */

    }
  }
  
	function callback() {
		if (req.readyState == 4) 
		{
			if (req.status == 200) 
			{
				var message = req.responseXML.getElementsByTagName("message")[0];  								
				retvalue=message.childNodes[0].nodeValue;
				if(retvalue=='IIC')
				{
					alert("Image code is not correct.");
					document.frmFeedback.keystring.focus();
				}				
				else if(retvalue=='sent')
				{					
					//alert("Feedback sent successfully.");	
					
					document.getElementById("tblFeedback").style.display='none';	
					document.getElementById("tblFeedbackMsg").style.display='';				
				}				
			}
		}
	}
	function callback5() {
		if (req.readyState == 4) 
		{
			if (req.status == 200) 
			{
				var message = req.responseXML.getElementsByTagName("message")[0];  								
				retvalue=message.childNodes[0].nodeValue;
				if(retvalue=='IIC')
				{
					alert("Image code is not correct.");
					document.frmContactus.keystring.focus();
				}				
				else if(retvalue=='sent')
				{					
					//alert("Feedback sent successfully.");	
					
					document.getElementById("tblContactus").style.display='none';	
					document.getElementById("tblContactusMsg").style.display='';				
				}				
			}
		}
	}
	function ReportAbuse(ID,Title)
	{
		Frm=this.document.frmFeedback;
		Frm.txtFeedbackType.value="Report Abuse ["+ Title +"]";
		Frm.cmbFeedbackType.value="Report Abuse";	
		Frm.txtMessage.value="";
		Frm.keystring.value="";
		Frm.hdnItemID.value=ID;
		HideObjects();
		document.getElementById('feedbackpopupbox').style.visibility="visible";
		document.getElementById("tblFeedbackMsg").style.display='none';	
		document.getElementById("tblFeedback").style.display='';
		if(Frm.txtName.type=="text") Frm.txtName.focus(); else Frm.txtMessage.focus();
	}
	function ContactUs()
	{
		Frm=this.document.frmContactus;
		Frm.cmbContactusType.value="Question";	
		Frm.txtMessage.value="";
		Frm.keystring.value="";
		Frm.hdnItemID.value="";
		HideObjects();
		document.getElementById('contactuspopupbox').style.visibility="visible";
		document.getElementById("tblContactusMsg").style.display='none';	
		document.getElementById("tblContactus").style.display='';
		if(Frm.txtName.type=="text") Frm.txtName.focus(); else Frm.txtMessage.focus();
	}
	
	function SendContactus()
	{
		Frm=this.document.frmContactus;
		var url = "managecontactus.php?name=" + escape(Frm.txtName.value)+"&email=" + escape(Frm.txtEmail.value)+"&message=" + escape(Frm.txtMessage.value)+"&itemid=" + escape(Frm.hdnItemID.value)+"&keystring=" + escape(Frm.keystring.value)+"&feedbacktype=" + escape(Frm.cmbContactusType.value); 

			if (window.XMLHttpRequest) {
				req = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			req.open("GET", url, true);
			req.onreadystatechange = callback5;
			req.send(null);			
	}
	
	function SendFeedback()
	{
		Frm=this.document.frmFeedback;
		var url = "managefeedback.php?name=" + escape(Frm.txtName.value)+"&email=" + escape(Frm.txtEmail.value)+"&message=" + escape(Frm.txtMessage.value)+"&itemid=" + escape(Frm.hdnItemID.value)+"&keystring=" + escape(Frm.keystring.value)+"&feedbacktype=" + escape(Frm.cmbFeedbackType.value); 

			if (window.XMLHttpRequest) {
				req = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			req.open("GET", url, true);
			req.onreadystatechange = callback;
			req.send(null);			
	}
  
	function  doPFKeyFeedback(e) {	  		
	  if(e.keyCode==13)	IsValidFeedBackData2();
	}	  
  function feedbackpopup(showhide){
    if(showhide == "show"){
		HideObjects();
		HideDropdowns();
		Frm=this.document.frmFeedback;
		Frm.txtFeedbackType.value="Suggestion";
		Frm.cmbFeedbackType.value="Suggestion";	
		Frm.txtMessage.value="";
		Frm.keystring.value="";
		Frm.hdnItemID.value='';
        document.getElementById('feedbackpopupbox').style.visibility="visible"; /* If the function is called with the variable 'show', show the login box */
		document.getElementById("tblFeedbackMsg").style.display='none';	
		document.getElementById("tblFeedback").style.display='';	
		if(Frm.txtName.type=="text") Frm.txtName.focus(); else Frm.txtMessage.focus();
    }else if(showhide == "hide"){
		ShowDropdowns();
        document.getElementById('feedbackpopupbox').style.visibility="hidden"; /* If the function is called with the variable 'hide', hide the login box */

    }
  }
  function IsValidContactusData2()
	{
		Frm=this.document.frmContactus;
		Err="";		
		Obj='';
		if (Frm.txtName.type!='hidden' && (Frm.txtName.value.length<1 || alpha(Frm.txtName.value)==false))
		{
			Err=Err+"Please enter valid Name .\n\r";
			if(Obj=='') Obj=Frm.txtName;
		}
		if (Frm.txtEmail.value=="" || !isValidEmail(Frm.txtEmail.value) )
		{
			Err=Err+"Please type valid Email .\n\r";
			if(Obj=='') Obj=Frm.txtEmail;
		}
		if (Frm.txtMessage.value.length<1)
		{
			Err=Err+"Please type valid Message .\n\r";
			if(Obj=='') Obj=Frm.txtMessage;
		}
		if (Frm.keystring.value.length<1)
		{
			Err=Err+"Please type image string to validate .\n\r";
			if(Obj=='') Obj=Frm.keystring;
		}
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	else SendContactus();
	}
  function  doPFKeyContactus(e) {	  		
	  if(e.keyCode==13)	IsValidContactusData2();
	}
  function contactuspopup(showhide){
    if(showhide == "show"){
		HideObjects();
		HideDropdowns();
		Frm=this.document.frmContactus;
		Frm.cmbFeedbackType.value="Question";	
		Frm.txtMessage.value="";
		Frm.keystring.value="";
		Frm.hdnItemID.value='';
        document.getElementById('contactuspopupbox').style.visibility="visible"; /* If the function is called with the variable 'show', show the login box */
		document.getElementById("tblContactusMsg").style.display='none';	
		document.getElementById("tblContactus").style.display='';	
		if(Frm.txtName.type=="text") Frm.txtName.focus(); else Frm.txtMessage.focus();
    }else if(showhide == "hide"){
		ShowDropdowns();
        document.getElementById('contactuspopupbox').style.visibility="hidden"; /* If the function is called with the variable 'hide', hide the login box */

    }
  }
  //=-=================== Search Form
  function ManageAdvanceControl(Action)
	{					
		if(document.getElementById("tblAdvance")!=null)
		{
			if (Action==0)  document.getElementById("tblAdvance").style.display='none';
			else document.getElementById("tblAdvance").style.display='';
		}	
	}
	//---------------------------------Feed Back Form
	function IsValidFeedBackData()
	{
		Frm=this.document.frmFeedback;
		Err="";		
		Obj='';
		if (Frm.txtName.value.length<1 || alpha(Frm.txtName.value)==false)
		{
			Err=Err+"Please enter valid Name .\n\r";
			if(Obj=='') Obj=Frm.txtName;
		}
		if (Frm.txtEmail.value=="" || !isValidEmail(Frm.txtEmail.value) )
		{
			Err=Err+"Please type valid Email .\n\r";
			if(Obj=='') Obj=Frm.txtEmail;
		}
		if (Frm.txtMessage.value.length<1)
		{
			Err=Err+"Please type valid Message .\n\r";
			if(Obj=='') Obj=Frm.txtMessage;
		}
		if (Frm.keystring.value.length<1)
		{
			Err=Err+"Please type image string to validate .\n\r";
			if(Obj=='') Obj=Frm.keystring;
		}
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	else return true;
	}
	function IsValidFeedBackData2()
	{
		Frm=this.document.frmFeedback;
		Err="";		
		Obj='';
		if (Frm.txtName.type!='hidden' && (Frm.txtName.value.length<1 || alpha(Frm.txtName.value)==false))
		{
			Err=Err+"Please enter valid Name .\n\r";
			if(Obj=='') Obj=Frm.txtName;
		}
		if (Frm.txtEmail.value=="" || !isValidEmail(Frm.txtEmail.value) )
		{
			Err=Err+"Please type valid Email .\n\r";
			if(Obj=='') Obj=Frm.txtEmail;
		}
		if (Frm.txtMessage.value.length<1)
		{
			Err=Err+"Please type valid Message .\n\r";
			if(Obj=='') Obj=Frm.txtMessage;
		}
		if (Frm.keystring.value.length<1)
		{
			Err=Err+"Please type image string to validate .\n\r";
			if(Obj=='') Obj=Frm.keystring;
		}
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	else SendFeedback();
	}
//		dateCheck(email.value,"%m/%d/%yyyy")==false

//----------------- Share Code
function sharepopup(showhide){
    if(showhide == "show"){
		HideObjects();
		HideDropdowns();
		Frm=this.document.frmShare;	
		document.getElementById('txtShareType').value="Site";
		Frm.txtAddresses.value="";		
		Frm.hdnItemID.value='';
        document.getElementById('sharepopupbox').style.visibility="visible"; /* If the function is called with the variable 'show', show the login box */
		document.getElementById("tblShareMsg").style.display='none';	
		document.getElementById("tblShare").style.display='';	
		if(Frm.txtName.type=="text") Frm.txtName.focus(); else Frm.txtAddresses.focus();
    }else if(showhide == "hide"){
		ShowDropdowns();
        document.getElementById('sharepopupbox').style.visibility="hidden"; /* If the function is called with the variable 'hide', hide the login box */

    }
  }
    function ShowDropdowns()
	{
		for (f = 0; f < document.forms.length; f++)
		{
			var elements = document.forms[f].elements;
			for (e = 0; e < elements.length; e++)
			{
				if (elements[e].type == "select-one")
				{
					elements[e].style.display = 'block';
				}
			}
		}	
	}
	function HideDropdowns()
	{
		for (f = 0; f < document.forms.length; f++)
		{
			var elements = document.forms[f].elements;
			// looping through all elements on certain form
			for (e = 0; e < elements.length; e++)
			{
				if (elements[e].type == "select-one")
				{
					elements[e].style.display = 'none';
				}
			}
		}
	}
	function ShareItem(ID,Title)
	{
		Frm=this.document.frmShare;
		if(ID=='') document.getElementById('txtShareType').value="Site"; else document.getElementById('txtShareType').value="Item [" + Title +"]";
		Frm.txtAddresses.value="";
		Frm.hdnItemID.value=ID;
		HideObjects();
		document.getElementById('sharepopupbox').style.visibility="visible";
		document.getElementById("tblShareMsg").style.display='none';	
		document.getElementById("tblShare").style.display='';
		if(Frm.txtName.type=="text") Frm.txtName.focus(); else Frm.txtAddresses.focus();
	}
	
	function callback3() {
		if (req.readyState == 4) 
		{
			if (req.status == 200) 
			{
				var message = req.responseXML.getElementsByTagName("message")[0];  								
				retvalue=message.childNodes[0].nodeValue;
				if(retvalue=='IS')
				{
					alert("Please type valid sender.");
					document.frmShare.txtName.focus();
				}
				if(retvalue=='ISE')
				{
					alert("Please type valid sender email.");
					document.frmShare.txtEmail.focus();
				}
				else if(retvalue=='sent')
				{					
					document.getElementById("tblShare").style.display='none';	
					document.getElementById("tblShareMsg").style.display='';				
				}				
			}
		}
	}
	function IsValidRecData2()
	{
		Frm=this.document.frmShare;
		Err="";		
		Obj='';
		if (Frm.txtName.type!='hidden' && (Frm.txtName.value.length<1 || alpha(Frm.txtName.value)==false))
		{
			Err=Err+"Please enter valid Name .\n\r";
			if(Obj=='') Obj=Frm.txtName;
		}
		if (Frm.txtEmail.value=="" || !isValidEmail(Frm.txtEmail.value) )
		{
			Err=Err+"Please type valid Email .\n\r";
			if(Obj=='') Obj=Frm.txtEmail;
		}
		if (Frm.txtAddresses.value.length<1)
		{
			Err=Err+"Please type valid Recipient Email Address .\n\r";
			if(Obj=='') Obj=Frm.txtAddresses;
		}
		if (Frm.txtAddresses.value.length>=1)
		{
			A=Frm.txtAddresses.value.split(",");
			for(i=0;i<=A.length-1;i++)
			{
				if(!isValidEmail(trim(A[i])))
				{
					Err=Err+"Please type valid Recipient Email Address .\n\r";
					if(Obj=='') Obj=Frm.txtAddresses;
					break;
				}				
			}
		}		
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	else SendShare();
	}
	
	function SendShare()
	{
		Frm=this.document.frmShare;
		
		var url = "manageshare.php?name=" + escape(Frm.txtName.value)+"&email=" + escape(Frm.txtEmail.value)+"&message=" + escape(Frm.txtAddresses.value)+"&itemid=" + escape(Frm.hdnItemID.value); 
			if (window.XMLHttpRequest) {
				req = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			req.open("GET", url, true);
			req.onreadystatechange = callback3;
			req.send(null);			
	}
  
	function  doPFKeyShare(e) {	  		
	  if(e.keyCode==13)	IsValidRecData2();
	}
	
	//----------------------------------------
	//----------------- Forgot Pass Code
function forgotpopup(showhide){
    if(showhide == "show"){
		HideObjects();
		HideDropdowns();
		//Frm=this.document.frmForgot;		
		document.getElementById('email').value="";		
        document.getElementById('forgotpopupbox').style.visibility="visible"; /* If the function is called with the variable 'show', show the login box */
		document.getElementById("tblForgotMsg").style.display='none';	
		document.getElementById("tblForgot").style.display='';	
		document.getElementById('email').focus();
    }else if(showhide == "hide"){
		ShowDropdowns();
        document.getElementById('forgotpopupbox').style.visibility="hidden"; /* If the function is called with the variable 'hide', hide the login box */

    }
  }	
	
	function callback4() {
		if (req.readyState == 4) 
		{
			if (req.status == 200) 
			{
				var message = req.responseXML.getElementsByTagName("message")[0];  								
				retvalue=message.childNodes[0].nodeValue;	
				if(retvalue=='BAN')
				{
					alert("Your login is currently banned, Contact Administrator.");
					document.getElementById('email').focus();
				}
				if(retvalue=='NF')
				{
					alert("No User found with this email.");
					document.getElementById('email').focus();
				}
				else if(retvalue=='sent')
				{					
					document.getElementById("tblForgot").style.display='none';	
					document.getElementById("tblForgotMsg").style.display='';				
				}			
			}
		}
	}
	
	function IsValidForgotData2()
	{
		//Frm=this.document.frmForgot;
		Err="";		
		Obj='';		
		strEmail=document.getElementById('email').value;
		if (strEmail=="" || !isValidEmail(strEmail) )
		{
			Err=Err+"Please type valid Email .\n\r";
			if(Obj=='') Obj=document.getElementById('email');
		}		
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	else SendForgot();
	}
	
	function SendForgot()
	{
		//Frm=this.document.frmForgot;		
		var url = "manageforgot.php?email=" + escape(document.getElementById('email').value); 
			if (window.XMLHttpRequest) {
				req = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			req.open("GET", url, true);
			req.onreadystatechange = callback4;
			req.send(null);			
	}
  
	function  doPFKeyForgot(e) {	  		
	  if(e.keyCode==13)	IsValidForgotData2();
	}	
	//----------------------------------------
	function HideObjects()
	{
		document.getElementById('feedbackpopupbox').style.visibility="hidden";
		document.getElementById('sharepopupbox').style.visibility="hidden";
		document.getElementById('forgotpopupbox').style.visibility="hidden";
		document.getElementById('popupbox').style.visibility="hidden"; 			
		document.getElementById('contactuspopupbox').style.visibility="hidden";
		document.getElementById('loadingpopupbox').style.visibility="hidden";
	}
	function IsValidSearchCriteria()
	{
		Err="";		
		Obj='';		
		Frm=this.document.form2;
		if (Frm.txtCreationDate.value!='' && Frm.txtCreationDate2.value!='')
		{
			d1 = new Date(Frm.txtCreationDate.value);
			d2 = new Date(Frm.txtCreationDate2.value);

			if (d1>d2)
			{
				Err=Err+"Creation from Date can't be less than creation to date.\n\r";
				if(Obj=='') Obj=Frm.txtTitle;
			}			
		}
		if (Frm.txtExpireDate.value!='' && Frm.txtExpireDate2.value!='')
		{
			d1 = new Date(Frm.txtExpireDate.value);
			d2 = new Date(Frm.txtExpireDate2.value);			
			if (d1>d2)
			{
				Err=Err+"Expire from Date can't be less than Expire to date.\n\r";
				if(Obj=='') Obj=Frm.txtTitle;
			}			
		}	
		
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	else true;
		
	}
	function IsValidChangePassword()
	{
		Err="";		
		Obj='';
		with(document.frmChangePass)
		{
			if (oldpassword.value=="")
			{
				Err=Err+"Please type valid Old Password .\n\r";
				if(Obj=='') Obj=oldpassword;
			}	
			if (newpassword.value=="")
			{
				Err=Err+"Please type valid New Password .\n\r";
				if(Obj=='') Obj=newpassword;
			}
			if (confirmnewpassword.value=="")
			{
				Err=Err+"Please type valid Confirm New Password .\n\r";
				if(Obj=='') Obj=confirmnewpassword;
			}
			if (validatePassword(newpassword.value)==false || validatePassword(confirmnewpassword.value)==false){
				Err=Err+"Please retype password.\n The only special characters allowed are \"!@#$%^&*\", Spaces are also not allowed.\n\r";
				if(Obj=='') Obj=newpassword;
			}
		}
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	//else SendForgot();
	}
	function ReloadWith(pageno)
	{
		with(document.MyPageForm)
		{
			page.value=pageno;
			submit();
		}
	}
 

   function showProgress(name)
   {
	   HideObjects();
       document.getElementById(name).style.visibility="visible";
       //prg = "<IMG SRC='<?=$vBasePath?>images/ajaxload.gif'> Loading, Please wait ...";
       //progressViewer = document.getElementById(name);
       //progressViewer.innerHTML = prg;
   }
   
   function hideProgress(name)
   {
	   document.getElementById(name).style.visibility="hidden";
       //progressViewer = document.getElementById(name);
       //progressViewer.innerHTML = "";
   }
   function SetCurMetro(SelMetro,SelWeek)
   {
	   with(document.frmMetroArea)
	   {
			hdnMetroID.value=SelMetro;
			hdnWeekID.value=SelWeek;
			submit();
		}
	}
	function CheckBoxes()
   {
	   with(document.form1)
	   {
		   if(chkAll.checked==true)
		   {
	  		    chkMonday.checked=false;
				chkTuesday.checked=false;
				chkWednesday.checked=false;
				chkThursday.checked=false;
				chkFriday.checked=false;
				chkSaturday.checked=false;
				chkSunday.checked=false;
			}
			else if(chkMonday.checked==true || chkTuesday.checked==true || chkWednesday.checked==true || chkThursday.checked==true || chkFriday.checked==true || chkSaturday.checked==true || chkSunday.checked==true)
			{
				chkAll.checked=false;
				}
			
			if(chkMonday.checked==true && chkTuesday.checked==true && chkWednesday.checked==true && chkThursday.checked==true && chkFriday.checked==true && chkSaturday.checked==true && chkSunday.checked==true)
			{
				chkMonday.checked=false;
				chkTuesday.checked=false;
				chkWednesday.checked=false;
				chkThursday.checked=false;
				chkFriday.checked=false;
				chkSaturday.checked=false;
				chkSunday.checked=false;
				chkAll.checked=true;
			}
		}
		   
	}
	
	function IsValidNearestDeals()
	{
		Frm=this.document.FindDeals;
		Err="";
		Obj='';
		if (Frm.txtTitle.value.length<1)
		{
			Err=Err+"Please type a valid Title. \n\r";
			if(Obj=='')	Obj=Frm.txtTitle;
		}
		if (Frm.txtZip.value=='' || validateZIP(Frm.txtZip.value)==false)
		{
			Err=Err+"Please type a valid Zip. \n\r";
			if(Obj=='')	Obj=Frm.txtZip;
		}
		if (Err.length>0){alert(Err); Obj.focus(); Obj.select(); return false;}	else window.open('http://local.google.com/maps?f=q&hl=en&geocode=&q='+Frm.txtTitle.value+'+'+Frm.txtZip.value+'&ie=UTF8&z=14');
	}
	function  doPFKeySearchDeal(e) {	  		
	  if(e.keyCode==13)	IsValidNearestDeals();
	}
