// JavaScript Document
function stripHTML(){
var re = /(<([^>]+)>)/gi;
for (i=0; i<arguments.length; i++)
arguments[i].value=arguments[i].value.replace(re, "")
}


<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

function BrowserType(){
	b = navigator.userAgent.toLowerCase();
	if (b.indexOf('opera')!=-1) return 'opera';
	else if (b.indexOf('msie 7')!=-1) return 'ie7';
	else if (b.indexOf('msie')!=-1)  return 'ie6';
	else if (b.indexOf('safari')!=-1) return 'safari';
	else if (b.indexOf('gecko')!=-1)  return 'gecko';
}

function trim(str)
{
	if(str)
		return str.replace(/^\s*|\s*$/g,"");
	else
		return "";
}

function IsValidNumber(frm_field, err_msg, minimum, maximum)
{
	var minimum = (minimum == null) ? "1" : minimum;
	var maximum = (maximum == null) ? "" : maximum;
	//alert(minimum);
	//alert(maximum);
	if(trim(frm_field.value)=="")
	{
		alert('Please enter ' + err_msg);
		frm_field.focus();
		return false
	}
	sort_val = trim(frm_field.value)
	if(isNaN(sort_val) || sort_val.indexOf(".") != -1 || parseInt(sort_val)<minimum)
	{
		alert('Please enter valid ' + err_msg);
		frm_field.focus();
		return false;
	}
	if(maximum && (parseInt(sort_val)>maximum))
	{
		alert(err_msg + ' can be ' + maximum + ' only');
		frm_field.focus();
		return false;
	}
	return true;
}

function IsValidFloat(frm_field, err_msg, minimum, maximum)
{
	var minimum = (minimum == null) ? "1" : minimum;
	var maximum = (maximum == null) ? "" : maximum;
	//alert(minimum);
	//alert(maximum);	
	if(frm_field.value=="")
	{
		alert('Please enter ' + err_msg);
		frm_field.focus();
		return false
	}	
	frm_field = document.getElementById(frm_field);
	sort_val = trim(frm_field.value);	
	if(isNaN(sort_val) || parseFloat(sort_val)<minimum)
	{
		alert('Please enter valid ' + err_msg);
		frm_field.focus();
		return false;
	}	
	if(maximum && (parseFloat(sort_val)>maximum))
	{
		alert(err_msg + ' can be ' + maximum + ' only');
		frm_field.focus();
		return false;
	}	
	return true;
}

function checkEnter(e)//e is event object passed from function invocation
{ 
	var characterCode //literal character code will be stored in this variable
	
	if(e && e.which)//if which property of event object is supported (NN4)
	{ 
		e = e;
		characterCode = e.which ;//character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
	{ 
		return true;
	}
	else
	{
		return false;
	}
}
function isEmpty(ele, error_message, title){
	if(ele){
		var title = (title == null) ? null : title;
		//alert(ele.value);
		value = trim(ele.value);
		if(title){		
			if(value=="" || value.toLowerCase()==title){
				alert(error_message);
				ele.focus();
				return true;
			}		
		}else{
			if(value==""){
				alert(error_message);
				ele.focus();
				return true;
			}		
		}
	}
	return false;
}

function isLimitsInvalid(elem, error_msg, minlimit, maxlimit){
	var minlimit = (minlimit == null) ? 0 : minlimit;
	var maxlimit = (maxlimit == null) ? 0 : maxlimit;
	elem.value = trim(elem.value);
	elemLength = elem.value.length;
	//alert(elemLength);
	if(elemLength < minlimit || elemLength > maxlimit){
		alert(error_msg);
		//elem.value = elem.value.substring(0, maxlimit);
		elem.focus();
		return true;	
	}
	return false;	
}
function checkURL(val)
{
	//var patt =  /(ftp|http|https):\/\/[wW]{3}\.[A-Za-z0-9\-]{3,}\.[A-Za-z]{2,3}/;
	var patt =  /[A-Za-z0-9\-]{3,}\.[A-Za-z]{2,3}/;
	var result;
	
	result = patt.test(val);
	return result;
}


function checkLoginForm(){
	if(isEmpty(document.getElementById('UserUserName'),"E-mail address should not be empty.") && isEmpty(document.getElementById('UserPassword'),"Password field should not be empty."))
		return false;
	else
		return true;
}
function checkforgotpassword(){
	var username = document.getElementById('UserUserName');
	if(username.value==""){
		alert("Email field should not be empty.");
		username.focus();
		return false;
	}else if(!checkEmail(username.value)){
		alert("Please enter valid Email-ID.");
		username.focus();
		return false;
	}
}

function checkEmail_old(myForm)
{ 
	flag=false;
	if (/^\w+([+\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(trim(myForm))) 
	{
			flag=true;
			flag=validate_tldextension(myForm);
	}
		
	if(flag==true){
		return true;	
	} else {
		return false;
	}
}
function validate_tldextension(email){
	
	fullemail=email
	validtldlist="com,net,org,us,in,biz,info,tv,cc,ws,uk,au,name,de,jp,be,at,uk,nz,cn,tw,jobs,am,fm,gs,ms,nu,tc,tk,vg,eu,me"
	validtldlistarr=validtldlist.split(",")
	svalidtldlist="co.uk,me.uk,org.uk,co.nz,co.in,net.nz,org.nz,com.cn,org.cn,net.cn,com.tw,org.tw,idv.tw,templetechnologies.com"
	svalidtldlistarr=svalidtldlist.split(",")
	fullemailarr=fullemail.split("@")
	dotcount=0
	for(i=0;i<fullemailarr[1].length;i++){
		if(fullemailarr[1].charAt(i)=="."){
			dotcount++;	
		}
	}
	if(dotcount==2){
		tldextention=fullemailarr[1].split(".")
		reqstring=tldextention[1]+"."+tldextention[2]
		flag1=false
		for(i=0;i<svalidtldlistarr.length;i++){
			if(reqstring==svalidtldlistarr[i]){
				flag1=true
			}
		}
	}else if (dotcount==1){
		tldextention=fullemailarr[1].split(".")
		reqstring=tldextention[1]
		flag1=false
		for(i=0;i<validtldlistarr.length;i++){
			if(reqstring==validtldlistarr[i]){
				flag1=true
			}
		}
	}else{
		flag1=false
	}
	if(flag1==true){
		return true
	} else {
		return false
	}	
}
function checkEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID");
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID");
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID");
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID");
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID");
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID");
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID");
		    return false
		 }
		
		var email_name = str.split("@");
		if(checkforspecialchars_email_name(email_name[0]))
		{
			return false;
		}
		
		if(checkforspecialchars_email_domain(email_name[1]))
		{
			return false;
		}
		
 		 return true					
	}
	
	
function checkFileType(imagePath)
{
	var pathLength = imagePath.length;
	var lastDot = imagePath.lastIndexOf(".");
	var fileType = imagePath.substring(lastDot+1,pathLength);
	fileType = fileType.toLowerCase();
	if(fileType == "gif" || fileType == "jpg" || fileType == "jpeg" || fileType == "png") {
		return true;
	} else {
		return false;
	}
}


function checkforspecialchars_email_name(text)
{
	var iChars = "`~!@#$%^&*()=[]\\\';,/{}|\":<>?";
	for (var i = 0; i < text.length; i++) 
		if (iChars.indexOf(text.charAt(i)) != -1) 
			return true;
	return false;
}


function checkforspecialchars_email_domain(text)
{
	var iChars = "`~!@#$%^&*()+=-_[]\\\';,/{}|\":<>?";
	for (var i = 0; i < text.length; i++) 
		if (iChars.indexOf(text.charAt(i)) != -1) 
			return true;
	return false;
}

function showHideCommentForm(){
	var comment = document.getElementById("comment");
	var commentDiv = document.getElementById("comment");
	
	if(commentDiv.style.display=='none'){
		commentDiv.style.display = 'block';
		location.href = '#comment';	
		document.getElementById("addComment").focus();
	}else{
		commentDiv.style.display = 'none';
	}	
}
	

function checksearchForm(){
	var SearchSearch = document.getElementById('SearchSearch');	
	if(trim(SearchSearch.value)==""){
		alert("Search should not be empty.");
		SearchSearch.focus();
		return false;
	}
	location.href=HTTP_BASE+'search/index/'+SearchSearch.value;
	return true;
}


function checkedchangepasswordForm(){
	
	var UserOldpassword = document.getElementById('UserOldpassword');
	var UserNewPassword = document.getElementById('UserNewPassword');
	var UserConfirmPassword = document.getElementById('UserConfirmPassword');
	//alert('fgdkhg');
	
		if(trim(UserOldpassword.value)==""){
			alert("Please enter the Old Password");
			UserOldpassword.focus();
			return false;
		}
		if(trim(UserNewPassword.value)==""){
			alert("Please enter the New Password");
			UserNewPassword.focus();
			return false;
		}
		if(trim(UserNewPassword.value).length<5){
			alert("Please enter minimum 5 characters for New Password");
			UserNewPassword.focus();
			return false;
		}
		if(trim(UserConfirmPassword.value)==""){
			alert("Please enter the Confirm Password");
			UserConfirmPassword.focus();
			return false;
		}
		if(trim(UserNewPassword.value)!=trim(UserConfirmPassword.value)){
			alert("New Password and Confirm Password mismatch.");
			UserConfirmPassword.focus();
			return false;
		}		
		return true;	
}
////////////////////////////////////////////////

function val_feedback(dont_ask){
	var dont_ask = (dont_ask == null) ? 0 : 1;
	var frm = document.getElementById('frm_feedback');
	var UserFeedbackFeedbackCommentsH = document.getElementById('UserFeedbackFeedbackCommentsH');
	var UserFeedbackFeedbackCommentsP = document.getElementById('UserFeedbackFeedbackCommentsP');
	var UserFeedbackStatus = document.getElementById('UserFeedbackStatus');
	UserFeedbackStatus.value=dont_ask;
	
/*	if(document.getElementById('feedback_type_0').checked==true)
	{
		if(trim(UserFeedbackFeedbackCommentsH.value)==""){
			alert('Please enter your feedback');
			UserFeedbackFeedbackCommentsH.focus();
			return false;
		}
	}
	if(document.getElementById('feedback_type_1').checked==true)
	{
		if(trim(UserFeedbackFeedbackCommentsP.value)==""){
			alert('Please enter your comments');
			UserFeedbackFeedbackCommentsP.focus();
			return false;
		}
	}
*/	frm.submit();
}


function checkreview(){
	//alert('hhh');
	var ReviewDescription = document.getElementById('ReviewReviewDescription');
	var review_rating = document.getElementById('review_rating');
	var value = review_rating.value;
	if(value==0){
		alert("Please enter a rating for your review.");
		review_rating.focus();
		return false;
	}
	if(trim(ReviewDescription.value)==""){
		alert("Review description should not be empty.");
		ReviewDescription.focus();
		return false;
	}
	return true;
}


function checkuseradd(){
	//alert('hhh');
	var UserFirstName = document.getElementById('UserFirstName');
	var UserLastName = document.getElementById('UserLastName');
	var email = document.getElementById('UserUserName');
	var UserPassword = document.getElementById('UserPassword');
	var UserRetypepassword = document.getElementById('UserRetypepassword');
	var city = document.getElementById('UserCityId');
	var country = document.getElementById('UserCountryId');
	var UserAvatarImage = document.getElementById('UserAvatarImage');
	var UserDateOfBirthMonth = document.getElementById('UserDateOfBirthMonth');
	var UserDateOfBirthDay = document.getElementById('UserDateOfBirthDay');
	var UserDateOfBirthYear = document.getElementById('UserDateOfBirthYear');
	
	//var ReviewDescription = document.getElementById('ReviewReviewDescription');
	
	
	if(trim(UserFirstName.value)==""){
		alert("Please enter your first name.");
		UserFirstName.focus();
		return false;
	}
	if(trim(UserLastName.value)==""){
		alert("Please enter your last name.");
		UserLastName.focus();
		return false;
	}
	if(trim(email.value)==""){
		alert("Please enter your email address.");
		email.focus();
		return false;
	}else if(!checkEmail(trim(email.value))){
		alert("Please enter valid Email-ID.");
		email.focus();
		return false;
	}
	email.value = trim(email.value)
	if(trim(UserPassword.value)==""){
		alert("Please enter a password.");
		UserPassword.focus();
		return false;
	}
	if(UserPassword.length<6){
		alert("Password length should be between 6.");
		UserPassword.focus();
		return false;
	}
	if(trim(UserRetypepassword.value)==""){
		alert("Please confirm your password.");
		UserRetypepassword.focus();
		return false;
	}
	if(trim(UserRetypepassword.value)!=trim(UserPassword.value)){
		alert("Your passwords do not match. Please enter and confirm your password.");
		UserPassword.value = '';
		UserRetypepassword.value = '';
		
		UserPassword.focus();
		return false;
	}
	if(
	   (trim(UserDateOfBirthMonth.value)=="0" && (trim(UserDateOfBirthDay.value)!="0" || trim(UserDateOfBirthYear.value)!="0"))
	   ||
	   (trim(UserDateOfBirthDay.value)=="0" && (trim(UserDateOfBirthMonth.value)!="0" || trim(UserDateOfBirthYear.value)!="0"))
	   ||
	   (trim(UserDateOfBirthYear.value)=="0" && (trim(UserDateOfBirthDay.value)!="0" || trim(UserDateOfBirthMonth.value)!="0"))
	   ){
		alert("Please select valid Birthdate.");
		return false;
	}
	
	if(trim(city.value)=="" || trim(city.value)=="0"){
		alert("City field should not be empty.");
		city.focus();
		return false;
	}
	
	if(trim(UserAvatarImage.value)!=""){
		if(checkFileType(UserAvatarImage.value)==false){
			//alert("Please select image of type 'jpg' or 'jpeg' or 'gif' or 'png' only.");
			alert("Only images with the following file extensions are accepted: .jpg, .jpeg, .png, .gif.");
			UserAvatarImage.focus();
			return false;
		}
	}
	return true;
}
function checkuseredit(){
	var UserFirstName = document.getElementById('UserFirstName');
	var UserLastName = document.getElementById('UserLastName');
	var email = document.getElementById('UserUserName');
	var UserPassword = document.getElementById('UserCurpassword');
	var UserNewpassword = document.getElementById('UserNewpassword');
	var UserRepassword = document.getElementById('UserRepassword');
	var city = document.getElementById('UserCityId');
	var country = document.getElementById('UserCountryId');
	var UserAvatarImage = document.getElementById('UserAvatarImage');
	var UserDateOfBirthMonth = document.getElementById('UserDateOfBirthMonth');
	var UserDateOfBirthDay = document.getElementById('UserDateOfBirthDay');
	var UserDateOfBirthYear = document.getElementById('UserDateOfBirthYear');
	
	if(trim(UserFirstName.value)==""){
		alert("First Name should not be empty.");
		UserFirstName.focus();
		return false;
	}
	if(trim(UserLastName.value)==""){
		alert("Last Name should not be empty.");
		UserLastName.focus();
		return false;
	}
	if(trim(email.value)==""){
		alert("Email field should not be empty.");
		email.focus();
		return false;
	}else if(!checkEmail(trim(email.value))){
		alert("Please enter valid Email-ID.");
		email.focus();
		return false;
	}	
	if(trim(UserPassword.value)!=""){
		if(trim(UserNewpassword.value)==""){
			alert("New Password should not be empty.");
			UserNewpassword.focus();
			return false;
		}
		if(trim(UserRepassword.value)==""){
			alert("Retype Password should not be empty.");
			UserRepassword.focus();
			return false;
		}
		if(UserRepassword.length<6){
			alert("Password length should be between 6.");
			UserRepassword.focus();
			return false;
		}
		if(trim(UserNewpassword.value)!=trim(UserRepassword.value)){
			alert("Password mismatch. Please re-enter.");
			UserRepassword.focus();
			return false;
		}
	}
	if(
	   (trim(UserDateOfBirthMonth.value)=="0" && (trim(UserDateOfBirthDay.value)!="0" || trim(UserDateOfBirthYear.value)!="0"))
	   ||
	   (trim(UserDateOfBirthDay.value)=="0" && (trim(UserDateOfBirthMonth.value)!="0" || trim(UserDateOfBirthYear.value)!="0"))
	   ||
	   (trim(UserDateOfBirthYear.value)=="0" && (trim(UserDateOfBirthDay.value)!="0" || trim(UserDateOfBirthMonth.value)!="0"))
	   ){
		alert("Please select valid Birthdate.");
		return false;
	}
	
	if(trim(city.value)==""){
		alert("City field should not be empty.");
		city.focus();
		return false;
	}
	if(trim(UserAvatarImage.value)!=""){
		if(checkFileType(UserAvatarImage.value)==false){
			//alert("Please select image of type 'jpg' or 'jpeg' or 'gif' or 'png' only.");
			alert("Only images with the following file extensions are accepted: .jpg, .jpeg, .png, .gif.");
			UserAvatarImage.focus();
			return false;
		}
	}
	return true;
}

function validate_search(frm)
{
	var key = trim(frm.search_key.value);
	if(key=="" || key=="Enter search key")
	{
		alert("Please enter search key");
		frm.search_key.focus();
		return false;
	}
	location.href=HTTP_BASE+'search/index/'+escape(encodeURI(key));
	return false;
}

function checkeditdesc(){
	var ListingListDescription = document.getElementById('ListingListDescription');
		var	ListingListWebUrl = document.getElementById('ListingListWebUrl');
	if(ListingListDescription && trim(ListingListDescription.value)==""){
		alert("Listing description should not be empty.");
		ListingListDescription.focus();
		return false;
	}	
	if(ListingListWebUrl){
		if(isEmpty(ListingListWebUrl, 'Please enter Website URL')) return false;			
		if(!checkURL(ListingListWebUrl.value)){					 
			alert("Please enter a valid Website URL");
			ListingListWebUrl.focus();
			return false;
		}
	}
}

function checkaddlisting(){
	var ListingListName = document.getElementById('ListingListName');
	var ListingListType = document.getElementById('ListingListType');
	var submit_button = document.getElementById('submit_button');
	if(trim(ListingListName.value)==""){
		alert("Listing name should not be empty.");
		ListingListName.focus();
		return false;
	}
	if(ListingListType.value==0){
		alert("Select Relationship.");
		ListingListType.focus();
		return false;
	}
	//submit_button.disabled = true;
}

function checkeditaddress(){
	var ListingListAddress = document.getElementById('ListingListAddress');
	var ListingListPhone=document.getElementById('ListingListPhone');
	var ListingListWebUrl=document.getElementById('ListingListWebUrl');
	var ListingListDirections=document.getElementById('ListingListDirections');
		if(trim(ListingListAddress.value)==""){
		alert("Address should not be empty.");
		ListingListAddress.focus();
		return false;
	}
	if(trim(ListingListPhone.value)==""){
		alert("Phone number should not be empty.");
		ListingListPhone.focus();
		return false;
	}
	if(isNaN(ListingListPhone.value)){
		alert("Please enter phone number in numericals");
		ListingListPhone.focus();
		return false;
	}
	if(trim(ListingListWebUrl.value)==""){
		alert("Website URL should not be empty.");
		ListingListWebUrl.focus();
		return false;
	}
	
	if(ListingListWebUrl.value!=""){
		if(!checkURL(ListingListWebUrl.value)){					 
			alert("Please enter a valid URL");
			ListingListWebUrl.focus();
			return false;
		}
	}
	
	if(trim(ListingListDirections.value)==""){
		alert("List Directions should not be empty.");
		ListingListDirections.focus();
		return false;
	}
	
}

function val_frm_def_cat(){		
	var category = document.getElementsByName('data[DefaultCategory][cat_id][]');
	var num_checked = 0;
	for(opt=0;opt<category.length;opt++){
		if(category[opt].checked==true){
			num_checked++;
		}
		if(num_checked>4)
			break;
	}
	if(num_checked>4 || num_checked<4){
		alert("Please select four categories.");
		return false;
	}
}

function val_ann()
{ 
	var AnnouncementAnnouncementTitle=document.getElementById('AnnouncementAnnouncementTitle');
	var AnnouncementAnnouncementDescription=document.getElementById('AnnouncementAnnouncementDescription');
	
	if(isEmpty(AnnouncementAnnouncementTitle, 'Please enter announcement Title', 'title')) return false;
	if(isEmpty(AnnouncementAnnouncementDescription, 'Please enter announcement description', 'description')) return false;
	//if(isLimitsInvalid(AnnouncementAnnouncementDescription, 'Announcement description should be only 150 words in length', 1, 150)) return false;
	return true;	
}
function couponnumber()
{
	var PaidUserCouponCode=document.getElementById('PaidUserCouponCode');	
	var PaidUserCardFname=document.getElementById('PaidUserCardFname');	
	var PaidUserCardLname=document.getElementById('PaidUserCardLname');
	var PaidUserAddrress1=document.getElementById('PaidUserAddrress1');
	var PaidUserAddrress2=document.getElementById('PaidUserAddrress2');
	var PaidUserCity=document.getElementById('PaidUserCity');
	var PaidUserState=document.getElementById('PaidUserState');
	var PaidUserZipcode=document.getElementById('PaidUserZipcode');
	var PaidUserCountry=document.getElementById('PaidUserCountry');
	var PaidUserCreditcardnumber=document.getElementById('PaidUserCreditcardnumber');
	var PaidUserCvv=document.getElementById('PaidUserCvv');
	var PaidUserExpiryMonthMonth=document.getElementById('PaidUserExpiryMonthMonth');
	var PaidUserExpiryYearYear=document.getElementById('PaidUserExpiryYearYear');
	
	if(trim(PaidUserCouponCode.value)==""){
		alert("Coupon Code should not be empty.");
		PaidUserCouponCode.focus();
		return false;
	}
	duplicate_elem(PaidUserCardFname, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserCardLname, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserAddrress1, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserAddrress2, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserCity, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserState, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserZipcode, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserCountry, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserCreditcardnumber, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserCvv, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserExpiryMonthMonth, 'CC', 'frm_coupon_code');
	duplicate_elem(PaidUserExpiryYearYear, 'CC', 'frm_coupon_code');
	return true;
}


function val_payment_info()
{
	var PaidUserCardname=document.getElementById('PaidUserCardFname');
	var PaidUserCardLname=document.getElementById('PaidUserCardLname');

	var PaidUserAddrress1=document.getElementById('PaidUserAddrress1');
	var PaidUserAddrress2=document.getElementById('PaidUserAddrress2');
	var PaidUserCity=document.getElementById('PaidUserCity');
	var PaidUserState=document.getElementById('PaidUserState');
	var PaidUserCountry=document.getElementById('PaidUserCountry');
	var PaidUserCreditcardnumber=document.getElementById('PaidUserCreditcardnumber');
	var PaidUserCvv=document.getElementById('PaidUserCvv');
	var PaidUserExpiration=document.getElementById('PaidUserExpiration');
	var PaidUserTerms=document.getElementById('PaidUserTerms');		
		
	if(trim(PaidUserCardname.value)==""){
		alert("Please enter the first name on your credit card.");
		PaidUserCardname.focus();
		return false;
	}
	if(trim(PaidUserCardLname.value)==""){
		alert("Please enter the last name on your credit card.");
		PaidUserCardLname.focus();
		return false;
	}
	if(trim(PaidUserAddrress1.value)==""){
		alert("Address1 should not be empty.");
		PaidUserAddrress1.focus();
		return false;
	}
	/*	if(trim(PaidUserAddrress2.value)==""){
		alert("Addrress2 should not be empty.");
		PaidUserAddrress2.focus();
		return false;
	}*/
	if(trim(PaidUserCity.value)==""){
		alert("City should not be empty.");
		PaidUserCity.focus();
		return false;
	}
	if(trim(PaidUserState.value)==""){
		alert("State should not be empty.");
		PaidUserState.focus();
		return false;
	}
		if(trim(PaidUserCountry.value)==""){
		alert("Country should not be empty.");
		PaidUserCountry.focus();
		return false;
	}
	if(trim(PaidUserCreditcardnumber.value)==""){
		alert("Credit card number should not be empty.");
		PaidUserCreditcardnumber.focus();
		return false;
	}
	if(isNaN(PaidUserCreditcardnumber.value)){
		alert("Please enter credit card number in numericals");
		PaidUserCreditcardnumber.focus();
		return false;
	}
		if(PaidUserCreditcardnumber.value.length<16){
		alert("Invalid credit card number.");
		PaidUserCreditcardnumber.focus();
		return false;
	}
	if(trim(PaidUserCvv.value)==""){
		alert("CVV should not be empty.");
		PaidUserCvv.focus();
		return false;
	}
	if(isNaN(PaidUserCvv.value)){
		alert("Please enter CVV in numericals");
		PaidUserCvv.focus();
		return false;
	}
	if(PaidUserCvv.value.length<3){
		alert("Invalid cvv number");
		PaidUserCvv.focus();
		return false;
	}
	if(PaidUserTerms.checked==false){
		alert("You must agree with the terms of service to sign up for a premium account.");
		PaidUserTerms.focus();
		return false;
	}
	return true;
}

function val_list_coupons()
{ 
	//alert('here');
	var ListCouponCouponTitle=document.getElementById('ListCouponCouponTitle');	
	var ListCouponCouponDescription=document.getElementById('ListCouponCouponDescription');
	var ListCouponCouponRestriction=document.getElementById('ListCouponCouponRestriction');
	
	if(isEmpty(ListCouponCouponTitle, 'Please enter Coupon title', 'title')) return false;
	if(isEmpty(ListCouponCouponDescription, 'Please enter Description', 'enter coupon description here....')) return false;
	if(isEmpty(ListCouponCouponRestriction, 'Please enter Restrictions', 'enter restriction details here....')) return false;
	if(isLimitsInvalid(ListCouponCouponDescription, 'Coupon description should be only 300 characters in length', 1, 300)) return false;
	if(isLimitsInvalid(ListCouponCouponRestriction, 'Coupon restriction should be only 150 characters in length', 1, 150)) return false;
	return true;	
}

//view coupon
function val_frm_cou(form){
	
	if(form.name=='frm_coupon'){
		
		var CouponCouponName = document.getElementById('CouponCouponName');	
		var CouponCouponCode = document.getElementById('CouponCouponCode');	
		var CouponCouponPercent = document.getElementById('CouponCouponPercent');	
		var CouponCouponExpiresOn = document.getElementById('CouponCouponExpiresOn');	
		var CouponCouponDuration = document.getElementById('CouponCouponDuration');
	}else if(form.name=='frm_edit_coupon'){
		
		var CouponCouponName = document.getElementById('CouponCouponNameE');	
		var CouponCouponCode = document.getElementById('CouponCouponCodeE');	
		var CouponCouponPercent = document.getElementById('CouponCouponPercentE');	
		var CouponCouponExpiresOn = document.getElementById('CouponCouponExpiresOnE');	
		var CouponCouponDuration = document.getElementById('CouponCouponDurationE');
		
	}

	if(trim(CouponCouponName.value)=="" || CouponCouponName.value=="Name"){
		alert("Coupon name should not be empty.");
		CouponCouponName.focus();
		return false;
	}
	if(trim(CouponCouponCode.value)=="" || CouponCouponCode.value=="Coupon Code"){
		alert("Coupon code should not be empty.");
		CouponCouponCode.focus();
		return false;
	}
	if(trim(CouponCouponPercent.value)=="" || CouponCouponPercent.value=="Percentage Off"){
		alert("Coupon percent should not be empty.");
		CouponCouponPercent.focus();
		return false;
	}
	if(isNaN(CouponCouponPercent.value)){
		alert("Coupon percent should be numeric.");
		CouponCouponPercent.focus();
		return false;
	}else if((CouponCouponPercent.value<=0) || (CouponCouponPercent.value>100)){
		alert("Coupon percent should be in between 1 and 100.");
		CouponCouponPercent.focus();
		return false;
	}
	if(trim(CouponCouponExpiresOn.value)=="" || CouponCouponExpiresOn.value=="yyyy-mm-dd"){
		alert("Expiry date should not be empty.");
		return false;
	}
	if(trim(CouponCouponDuration.value)==""){
		alert("Coupon duration should not be empty.");
		return false;
	}
	if(isNaN(CouponCouponDuration.value)){
		alert("Coupon duration should be numeric.");
		CouponCouponDuration.focus();
		return false;
	}
	if(CouponCouponDuration.value.length>2){
		alert("Coupon duration should be two digits only.");
		CouponCouponDuration.focus();
		return false;
	}

	var selectedDate = CouponCouponExpiresOn.value;
	
	var dd = selectedDate.split('-');
	selectedDate = trim(dd[2])+"-"+dd[0]+"-"+dd[1]+" ";
	
	var firstIndex = selectedDate.indexOf('-');
	
	var Y = parseInt(selectedDate.substring(0, firstIndex));
	selectedDate = selectedDate.substring(++firstIndex);
	
	
	firstIndex = selectedDate.indexOf('-');
	var M = parseInt(selectedDate.substring(0, firstIndex));
	selectedDate = selectedDate.substring(++firstIndex);
	M--;
	
	var D = parseInt(selectedDate)
	//alert(Y+' : '+M+' : '+D);
	//--------------------------
	var SelDate=new Date();
	
	SelDate.setFullYear(Y, M, D);
	//alert(SelDate);
	var today = new Date();
	
	if (SelDate<today)	
	{
		alert("Date must be greater than or equal to today's date");
		CouponCouponExpiresOn.focus();
		return false;
	}

return true;
}

//view coupon
function funclick(form,type){
	var frm=document.frm_coupon;
	var flag=false;
		if(frm)
		{
			for(i=0;i<frm.elements.length;i++)
			{	
				if(frm.elements[i].name=="data[Coupon][id]" && frm.elements[i].checked )
				{
					if(type == 'edit')
					window.location="../coupons/edit/"+(frm.elements[i].value)
					if(type == 'delete'){
					lightbox_alert('<div align="center">Are you sure you would like to cancel</div><br><div align="center"><input type="button" value="ok" onclick="delete_coupon('+frm.elements[i].value+')">&nbsp;<input type="button" value="Cancel" onclick="..coupons/view"></div>');
					}
					flag=true;
					return true;
				}
			}	
			if(!flag)
			{					
				alert('Select coupon');
				return false;
			}
		}
	return false;
}

//delete coupon
function delete_coupon(coupon_id){
	window.location="../coupons/delete/"+(coupon_id);
}
/*function val_listins(){
	var listcheck = document.getElementById('listcheck');
		//alert():
		if(trim(listcheck.checked)=="" ){
		alert("Please check any listing ");
		listcheck.focus();
		return false;
	}
	return true;
}*/

function ajax_call(div_id, url){
	//alert('div_id: '+div_id+'\n'+'url: '+url);
	if(document.getElementById(div_id))
		new Ajax.Updater(div_id,url, {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', div_id]});
}

function enableSelectTag(ele){
	//alert(ele.value);
	if(ele.value==0){
		document.getElementById('Pdiv').style.display='none';	
		document.getElementById('Hdiv').style.display='block';
	}else{
		document.getElementById('Pdiv').style.display='block';
		document.getElementById('Hdiv').style.display='none';
	}
}

function frm_submit(frm_id){
	var frm_id = (frm_id == null) ? null : frm_id;
	if(frm_id)
		if(document.getElementById(frm_id))
			document.getElementById(frm_id).submit();
}

function show_elem(elem){
	var filt = document.getElementById(elem);
	//alert(filt.toArray());
	//*
	var str= '';
	for(var i in filt){
		str = str + i+'---'+filt[i]+'\n';	
	}
	//alert(str);
	document.write(str);
}
function loading_div(div_id){
	var div_width = document.getElementById(div_id).offsetWidth;
	var div_height = document.getElementById(div_id).offsetHeight;	
	
	var padWid = (div_width-100)/2 +'px';
	var padTop = (div_height-100)/2 +'px';
	
	document.getElementById(div_id).innerHTML = '<div style="postion:relative; padding-left:'+padWid+';padding-top:'+padTop+';"><div style="background-color:#FFFFFF; color:#660000; border:1px solid #660000;padding:2px;font-weight: bold; width:111px;"><img src="'+HTTP_BASE+'img/loading.gif" border="0" align="absmiddle" />&nbsp;&nbsp;&nbsp;Loading...</div></div>';
}
	
function loading_div_mask(div_id, abs_elem){

	var abs_elem = (abs_elem == null) ? false : true;
	
	var div_width = document.getElementById(div_id).offsetWidth;
	var div_height = document.getElementById(div_id).offsetHeight;	
	var div_left = document.getElementById(div_id).offsetLeft;	
	var div_top = document.getElementById(div_id).offsetTop;
	//show_elem(div_id);
	//alert(div_left+'--'+div_top);
	var padWid = (div_width-100)/2 +'px';
	var padTop = (div_height-100)/2 +'px';
	
	var appWH = ' width:'+div_width+'px;height:'+div_height+'px;';
	if(abs_elem==true)
		var appLT  = ' top:0px;left:0px;';
	else
		var appLT = ' top:'+div_top+'px;left:'+div_left+'px;';	
	
	var appPad = ' margin-left:'+padWid+';margin-top:'+padTop+';';
	var div_op = 5;
	
	//alert(div_id+':\n'+'appWH: '+appWH+' \nappLT: '+appLT+' \nappPad: '+appPad);
	var load_img = '<img src="'+HTTP_BASE+'img/loading.gif" border="0" align="absmiddle" />&nbsp;&nbsp;&nbsp;Loading...'
	map_div = document.getElementById(div_id);
	//map_div.style.opacity=0.9;
	
	var map_child = document.createElement('div');	
	map_child.innerHTML = '<div style="position:absolute; background-color:#FFFFFF; '+appLT+''+appWH+' filter:alpha(opacity='+div_op+'0); -moz-opacity:.'+div_op+'; opacity:.'+div_op+';"></div><div style="position:absolute; background-color:#FFFFFF; color:#660000; border:1px solid #660000; '+appLT+''+appPad+' padding:2px;font-weight: bold;">'+load_img+'</div>';
	map_div.appendChild(map_child);
}

function generate_elem(elem, name, frm_name, name_value){
	var name_value = (name_value == null) ? 0 : name_value;
	var frm = document.getElementById(frm_name);
	if(elem.checked==false){
		if(document.getElementById(name+elem.value))
			frm.removeChild(document.getElementById(name+elem.value));
	}else{//alert(name+elem.value);
		if(!document.getElementById(name+elem.value)){
			var check = document.createElement('input');
			check.type = 'hidden';
			if(name_value==0)
				check.name = name+'[]';
			else
				check.name = name+'['+name_value+'][]';
			check.id = name+elem.value;
			check.value = elem.value;
			check.checked = true;
			frm.appendChild(check);
		}
	}
}

function create_elem(elem, name, frm_name, name_value){
	var name_value = (name_value == null) ? 0 : name_value;
	var frm = document.getElementById(frm_name);
	if(!document.getElementById(name+elem)){
		var check = document.createElement('input');
		check.type = 'hidden';
		if(name_value==0)
			check.name = name+'[]';
		else
			check.name = name+'['+name_value+'][]';
		check.id = name+elem;
		check.value = elem;
		frm.appendChild(check);
	}
}

function remove_elem(elem, name, frm_name, name_value){
	var name_value = (name_value == null) ? 0 : name_value;
	var frm = document.getElementById(frm_name);
	if(document.getElementById(name+elem))
		frm.removeChild(document.getElementById(name+elem));
}

function duplicate_elem(elem, name, frm_name){
	var frm = document.getElementById(frm_name);
	if(typeof document.forms[frm_name].name != 'undefined'){
		var check = document.createElement('input');
		check.type = 'hidden';
		check.name = elem.name;
		check.id = elem.id;
		check.value = elem.value;
		frm.appendChild(check);
	}
}

function change_city(id){
	var previous_city = document.getElementById('previous_city').value;
	document.getElementById('new_city').value = id;
	document.getElementById('previous_city').value = id;
	document.getElementById('city_'+id).className = 'g_cursor g_f13 g_bold';
	document.getElementById('city_'+previous_city).className = 'g_link_color g_cursor g_f13 g_bold';
}

function val_change_city(){
	var frm = document.getElementById('frm_change_city');
	frm.submit();
}
	
function limit(what,chars,counter) {
	if (what.value.length > chars) {
		what.value=what.value.substr(0,chars);
		alert('Announcement description is limited to 500 characters.');
	}
	
	counting = (chars - what.value.length);
	c = document.getElementById(counter); 
	c.innerHTML = counting;
}			

function call_lightbox(url, left){
	var left = (left == null) ? 250 : left;
	document.getElementById('feedback_div').style.display='block';
	document.getElementById('feedback_auto').style.left=left+'px';
	ajax_call('feedback_auto',url);
}

function load_last(){
	for(i=1;i<=10;i++){
		if(document.getElementById('load_last'+i)){
			document.getElementById('load_last'+i).style.display='block';	
		}
	}
}

function checkLoginForm(){
	var UserUserName = document.getElementById('UserUserName');
	var UserPassword = document.getElementById('UserPassword');
	if(trim(UserUserName.value)==""){
		alert("E-mail address should not be empty.");
		UserUserName.value = '';
		UserUserName.focus();
		return false;
	}else if(!checkEmail(UserUserName.value)){
		alert("Please enter valid Email address.");
		UserUserName.focus();
		return false;
	}
	UserUserName.value = trim(UserUserName.value);
	if(trim(UserPassword.value)==""){
		alert("Password field should not be empty.");
		UserPassword.value = '';
		UserPassword.focus();
		return false;
	}
}