//---------- Function(s) ----------//

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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 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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}


function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function confirmCouponDelete()
{
var agree=confirm("Are you sure you want to delete this coupon?");
if (agree)
	return true ;
else
	return false ;
}

function confirmPageDelete()
{
var agree=confirm("Are you sure you want to delete this page?");
if (agree)
	return true ;
else
	return false ;
}
function confirmDealDelete()
{
var agree=confirm("Are you sure you want to delete this deal?");
if (agree)
	return true ;
else
	return false ;
}

function confirmRegDelete()
{
var agree=confirm("Are you sure you want to delete this region?");
if (agree)
	return true ;
else
	return false ;
}

function confirmCouponDelete()
{
var agree=confirm("Are you sure you want to delete this coupon?");
if (agree)
	return true ;
else
	return false ;
}
function confirmUserads()
{
var agree=confirm("Are you sure you want to delete this advertise?");
if (agree)
	return true ;
else
	return false ;
}

function nameval(tag)
{    
	var1=tag.value; // tval is textbox(element) checking for characters only
    s=var1.substr(var1.length-1,1); 	 
	m=s.charCodeAt(0);            
	if(!((m>=97 && m<=122 )||(m>=65 && m<=90)||(m==32) || (m==46) || isNaN(m)))
	{		
		ch=var1.substr(0,var1.length-1);		
		tag.value=ch;						
	}
}

function namevalchk(tag)
{    
	var1=tag.value; // tval is textbox(element) checking for characters only
    s=var1.substr(var1.length-1,1); 	 
	m=s.charCodeAt(0);            
	if(!((m>=97 && m<=122 )||(m>=65 && m<=90)||(m==32) || (m==46) || isNaN(m)))
	{		
		ch=var1.substr(0,var1.length-1);		
		tag.value=ch;						
	}
}

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

function isEmail(str)
{
	// Should not beging with a '.' or '@'
	if(str.charAt(0)=='@' || str.charAt(0) == '.')
	{	
		return false;
	}

    var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
    return regex.test(str);
}
function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}
function checkMobile(MobileNumber)
{
	if(isNaN(MobileNumber))
	{
		return false;
	}
	else if(MobileNumber.length != 10)
	{
		return false;
	}
	else if(!(MobileNumber.charAt(0) == '9' || MobileNumber.charAt(0) == '8' || MobileNumber.charAt(0) == '7'))
	{
		return false;
	}

	return true;
}
function phoneval(tag)
{    
	var1=tag.value; // tval is textbox(element) checking for characters only
    s=var1.substr(var1.length-1,1); 	 
	m=s.charCodeAt(0);            
	if(((m>=32 && m<=42) ||  (m==46)||(m==45) || (m>=58 && m<=126)))
	{		
		ch=var1.substr(0,var1.length-1);		
		tag.value=ch;						
	}
}
function confirmCatDelete()
{
var agree=confirm("Are you sure you want to delete this category? This will also delete all the corresponding records.");
if (agree)
	return true ;
else
	return false ;
}
function confirmTemplateDelete()
{
var agree=confirm("Are you sure you want to delete this template?");
if (agree)
	return true ;
else
	return false ;
}
function confirmCityDelete()
{
var agree=confirm("Are you sure you want to delete this city?");
if (agree)
	return true ;
else
	return false ;
}
function confirmUserDelete()
{
var agree=confirm("Are you sure you want to delete this user?");
if (agree)

	return true ;
else
	return false ;
}
function deleteCompany()
{
	var agree=confirm("Are you sure you want to delete this company?");
if (agree)
	return true ;
else
	return false ;
}

function deleteComment()
{
	var agree=confirm("Are you sure you want to delete this comment?");
if (agree)
	return true ;
else
	return false ;
}

function deleteNewsLetters()
{
	var agree=confirm("Are you sure you want to delete this newsletter?");
if (agree)
	return true ;
else
	return false ;
}
function adminLogin()
{
	elForm = document.login;
	
	if(trim(elForm.mobile.value)=="")
	{
		alert("Please enter mobile no.")
		elForm.mobile.focus();
		return false;
	}
	
	if(trim(elForm.password.value)=="")
	{
		alert("Please enter password.")
		elForm.password.focus();
		return false;
	}
}
function validateUserregistration()
{
	elForm = document.dataform;
	
	if(trim(elForm.first_name.value)=="")
	{
		alert("Please enter first name.")
		elForm.first_name.focus();
		return false;
	}
	
	if(trim(elForm.last_name.value)=="")
	{
		alert("Please enter last name.")
		elForm.last_name.focus();
		return false;
	}
	
	if(trim(elForm.mobile.value) == '')
    {
        alert('Please enter mobile no.');
        elForm.mobile.focus();
        return false;
    }
	if(isNaN(elForm.mobile.value))
    {
        alert('Please enter mobile no in numeric.');
        elForm.mobile.focus();
        return false;
    }
	if(!checkMobile(elForm.mobile.value))
    {
        alert('Please enter a valid mobile number starting with 9,8 or 7.');
        elForm.mobile.focus();
        return false;
    }
	
	if(trim(elForm.email.value)=="")
	{
		alert("Please enter email address.")
		elForm.email.focus();
		return false;
	}
	if(!isEmail((elForm.email.value)))
    {
        alert('Please enter a valid email address.');
        elForm.email.focus();
        return false;
    }
	if(elForm.city.value=="")
	{
		alert("Please select city.")
		elForm.city.focus();
		return false;
	}
	if(elForm.day.value=="")
	{
		alert("Please select day.")
		elForm.day.focus();
		return false;
	}
	if(elForm.month.value=="")
	{
		alert("Please select month.")
		elForm.month.focus();
		return false;
	}
	if(elForm.year.value=="")
	{
		alert("Please select year.")
		elForm.year.focus();
		return false;
	}
	
	if(elForm.address.selectedIndex==0)
	{
		alert("Please select location.")
		elForm.address.focus();
		return false;
	}
	
	/*if(trim(elForm.membership_no.value)=='')
	{
		alert("Please enter membership number.")
		elForm.membership_no.focus();
		return false;
	}*/
	
	if(trim(elForm.expiry_date.value)=='')
	{
		alert("Please enter expiry date.")
		elForm.expiry_date.focus();
		return false;
	}
	
	if((!elForm.status[0].checked)&&(!elForm.status[1].checked))
	{
		alert("Please check on status.");
		elForm.status[0].focus();
		return false;
	}
}

function validateNewUser()
{
	elForm = document.dataform;
	
	if(trim(elForm.first_name.value)=="")
	{
		alert("Please enter first name.")
		elForm.first_name.focus();
		return false;
	}
	
	if(trim(elForm.last_name.value)=="")
	{
		alert("Please enter last name.")
		elForm.last_name.focus();
		return false;
	}
	
	if(trim(elForm.mobile.value) == '')
    {
        alert('Please enter mobile no.');
        elForm.mobile.focus();
        return false;
    }
	if(isNaN(elForm.mobile.value))
    {
        alert('Please enter mobile no in numeric.');
        elForm.mobile.focus();
        return false;
    }
	if(!checkMobile(elForm.mobile.value))
    {
        alert('Please enter a valid mobile number starting with 9,8 or 7.');
        elForm.mobile.focus();
        return false;
    }
	
	if(trim(elForm.email.value)=="")
	{
		alert("Please enter email address.")
		elForm.email.focus();
		return false;
	}
	if(!isEmail((elForm.email.value)))
    {
        alert('Please enter a valid email address.');
        elForm.email.focus();
        return false;
    }
	
	if(elForm.day.value=="")
	{
		alert("Please select day.")
		elForm.day.focus();
		return false;
	}
	if(elForm.month.value=="")
	{
		alert("Please select month.")
		elForm.month.focus();
		return false;
	}
	if(elForm.year.value=="")
	{
		alert("Please select year.")
		elForm.year.focus();
		return false;
	}
	if(elForm.city.selectedIndex==0)
	{
		alert("Please select city.")
		elForm.city.focus();
		return false;
	}
	if(elForm.address.selectedIndex==0)
	{
		alert("Please select location.")
		elForm.address.focus();
		return false;
	}
}


function validateCategory()
{
	elForm = document.dataform;
	
	if(trim(elForm.cat_name.value)=='')
	{
		alert("Please enter category name.")
		elForm.cat_name.focus();
		return false;
	}
}

function validateCity()
{
	elForm = document.dataform;
	
	if(trim(elForm.city_name.value)=='')
	{
		alert("Please enter city name.")
		elForm.city_name.focus();
		return false;
	}
}

function validateSubCategory()
{
	elForm = document.dataform;
	
	if(trim(elForm.parent_id.value)=='')
	{
		alert("Please select parent category.")
		elForm.parent_id.focus();
		return false;
	}
	if(trim(elForm.cat_name.value)=='')
	{
		alert("Please enter category name.")
		elForm.cat_name.focus();
		return false;
	}
}

function validateLocation()
{
	elForm = document.dataform;
	
	if(trim(elForm.city_id.value)=='')
	{
		alert("Please select city.")
		elForm.city_id.focus();
		return false;
	}
	
	if(trim(elForm.location.value)=='')
	{
		alert("Please enter location.")
		elForm.location.focus();
		return false;
	}
}

function validateCompany()
{
	elForm = document.dataform;
	
	if(trim(elForm.cat_id.value)=='')
	{
		alert("Please select category.")
		elForm.cat_id.focus();
		return false;
	}
	if(trim(elForm.sub_cat_id.value)=='')
	{
		alert("Please select subcategory name.")
		elForm.sub_cat_id.focus();
		return false;
	}
	if(trim(elForm.company_name.value)=='')
	{
		alert("Please enter company name.")
		elForm.company_name.focus();
		return false;
	}
	/*if(trim(elForm.company_logo.value)=='')
	{
		alert("Please select company logo.")
		elForm.company_logo.focus();
		return false;
	}*/
	if(trim(elForm.company_username.value)=='')
	{
		alert("Please enter company username.")
		elForm.company_username.focus();
		return false;
	}
	if(trim(elForm.company_password.value)=='')
	{
		alert("Please enter company password.")
		elForm.company_password.focus();
		return false;
	}
	if(trim(elForm.description.value)=='')
	{
		alert("Please enter description.")
		elForm.description.focus();
		return false;
	}
}

function validateBanners()
{
	elForm = document.dataform;
	
	if(trim(elForm.company_name.value)=='')
	{
		alert("Please enter company name.")
		elForm.company_name.focus();
		return false;
	}
	if(trim(elForm.order.value)=='')
	{
		alert("Please enter order.")
		elForm.order.focus();
		return false;
	}
	if(trim(elForm.url.value)=='')
	{
		alert("Please enter Link.")
		elForm.url.focus();
		return false;
	}
	if(!isUrl(elForm.url.value))
	{
		alert("Please enter valid Link.")
		elForm.url.focus();
		return false;
	}
}

function templateValidation()
{
	elForm = document.dataform;
	
	if(trim(elForm.template_name.value)=='')
	{
		alert("Please select template.")
		elForm.template_name.focus();
		return false;
	}
	
}

function validateAddCoupon()
{
	elForm = document.dataform
	
	if(trim(elForm.coupon_title.value)=='')
	{
		alert("Please enter coupon title.")
		elForm.coupon_title.focus();
		return false;
	}
	
	/*if(!elForm.featured.checked && !elForm.spotlight.checked)
	{
		alert("Please check featured or spotlight.");
		elForm.featured.focus();
		return false;
	}*/
	
	if(trim(elForm.save_money.value)=='')
	{
		alert("Please enter Save % Or Rs.")
		elForm.save_money.focus();
		return false;
	}
	
	if(!elForm.coupon_type_1.checked && !elForm.coupon_type_2.checked && !elForm.coupon_type_3.checked)
	{
		alert("Please check Offer available on SMS or Membership Card or Print.");
		elForm.coupon_type_1.focus();
		return false;
	}
	
	if(elForm.coupon_type_1.checked)
	{
		if(trim(elForm.coupon_code_1.value)=='')
		{
			alert("Please enter code for sms.")
			elForm.coupon_code_1.focus();
			return false;
		}	
	}
	
	/*if(elForm.coupon_type_2.checked)
	{
		if(trim(elForm.coupon_code_2.value)=='')
		{
			alert("Please enter membership value.")
			elForm.coupon_code_2.focus();
			return false;
		}	
	}*/
	
	var edit = elForm.hidden_edit.value;
	
	if(edit=="")
	{
		if(elForm.coupon_type_3.checked)
		{
			if(trim(elForm.image.value)=='')
			{
				alert("Please select image.")
				elForm.image.focus();
				return false;
			}
			
			if(elForm.image.value)
			{
				var imgpath = elForm.image.value;
				
				if(imgpath != "")
				{
					 var arr1 = new Array;
					 arr1 = imgpath.split("\\");
					 var len = arr1.length;
					 var img1 = arr1[len-1];
					 var filext = img1.substring(img1.lastIndexOf(".")+1);
					 
					 if(filext == "jpg" || filext == "jpeg" || filext == "gif" || filext == "bmp" || filext == "png")
					 {
						return true; 
					 }
					 else
					 {
						alert("Please upload a valid (.jpg, .png, .bmp, .gif) file only.");
						elForm.image.focus();
						return false;
					 }
				}
			}
		}
	}
	/*else 
	if(edit!="")<!-- Editing time image validation -->
	{
			
	}*/
	
	if(elForm.category.selectedIndex==0)
	{
		alert("Please select category.")
		elForm.category.focus();
		return false;
	}
	
	if(elForm.sub_cat_id.selectedIndex==0)
	{
		alert("Please select sub-category.")
		elForm.sub_cat_id.focus();
		return false;
	}
	
	if(elForm.merchant_name.selectedIndex==0)
	{
		alert("Please select merchant name.")
		elForm.merchant_name.focus();
		return false;
	}
	
	if(trim(elForm.expired_date.value)=='')
	{
		alert("Please enter expiry date.")
		elForm.expired_date.focus();
		return false;
	}
	
	if(edit=="")
	{
		if(elForm.city_0.selectedIndex==0)
		{
			alert("Please select city.")
			elForm.city_0.focus();
			return false;
		}
		
		if(elForm.location_0.selectedIndex==0)
		{
			alert("Please select location.")
			elForm.location_0.focus();
			return false;
		}
	}
}

function validateAddCmpCoupon()
{
	elForm = document.dataform
	
	if(trim(elForm.coupon_title.value)=='')
	{
		alert("Please enter coupon title.")
		elForm.coupon_title.focus();
		return false;
	}
	
	if(trim(elForm.save_money.value)=='')
	{
		alert("Please enter Save % Or Rs.")
		elForm.save_money.focus();
		return false;
	}
	
	if(!elForm.coupon_type_1.checked && !elForm.coupon_type_2.checked && !elForm.coupon_type_3.checked)
	{
		alert("Please check Offer available on SMS or Membership Card or Print.");
		elForm.coupon_type_1.focus();
		return false;
	}
	
	if(elForm.coupon_type_1.checked)
	{
		if(trim(elForm.coupon_code_1.value)=='')
		{
			alert("Please enter code for sms.")
			elForm.coupon_code_1.focus();
			return false;
		}	
	}
	
	/*if(elForm.coupon_type_2.checked)
	{
		if(trim(elForm.coupon_code_2.value)=='')
		{
			alert("Please enter membership value.")
			elForm.coupon_code_2.focus();
			return false;
		}	
	}*/
	
	var edit = elForm.hidden_edit.value;
	
	if(edit=="")
	{
		if(elForm.coupon_type_3.checked)
		{
			if(trim(elForm.image.value)=='')
			{
				alert("Please select image.")
				elForm.image.focus();
				return false;
			}
			
			if(elForm.image.value)
			{
				var imgpath = elForm.image.value;
				
				if(imgpath != "")
				{
					 var arr1 = new Array;
					 arr1 = imgpath.split("\\");
					 var len = arr1.length;
					 var img1 = arr1[len-1];
					 var filext = img1.substring(img1.lastIndexOf(".")+1);
					 
					 if(filext == "jpg" || filext == "jpeg" || filext == "gif" || filext == "bmp" || filext == "png")
					 {
						return true; 
					 }
					 else
					 {
						alert("Please upload a valid (.jpg, .png, .bmp, .gif) file only.");
						elForm.image.focus();
						return false;
					 }
				}
			}
		}
	}
	/*else 
	if(edit!="")<!-- Editing time image validation -->
	{
			
	}*/
	
	if(trim(elForm.expired_date.value)=='')
	{
		alert("Please enter expiry date.")
		elForm.expired_date.focus();
		return false;
	}
	
	if(edit=="")
	{
		if(elForm.city_0.selectedIndex==0)
		{
			alert("Please select city.")
			elForm.city_0.focus();
			return false;
		}
		
		if(elForm.location_0.selectedIndex==0)
		{
			alert("Please select location.")
			elForm.location_0.focus();
			return false;
		}
	}
}


function validateSuggestCoupon()
{
	elForm = document.dataform
	
	if(trim(elForm.coupon_title.value)=='')
	{
		alert("Please enter coupon title.")
		elForm.coupon_title.focus();
		return false;
	}
	
	/*if(trim(elForm.save_money.value)=='')
	{
		alert("Please enter Save % Or Rs.")
		elForm.save_money.focus();
		return false;
	}
	
	if(elForm.category.selectedIndex==0)
	{
		alert("Please select category.")
		elForm.category.focus();
		return false;
	}
	
	if(elForm.sub_cat_id.selectedIndex==0)
	{
		alert("Please select sub-category.")
		elForm.sub_cat_id.focus();
		return false;
	}*/
	
	if(trim(elForm.merchant_name.value)=='')
	{
		alert("Please enter merchant name.")
		elForm.merchant_name.focus();
		return false;
	}
	
	if(trim(elForm.offer_description.value)=='')
	{
		alert("Please enter offer description.")
		elForm.offer_description.focus();
		return false;
	}
	
	if(trim(elForm.contact_details.value)=='')
	{
		alert("Please enter contact details.")
		elForm.contact_details.focus();
		return false;
	}
}


function newsletterValidation()
{
	elForm = document.dataform;
	
	if((!elForm.newsletter_type[0].checked) && (!elForm.newsletter_type[1].checked))
	{
		alert("Please select newsletter type.")
		elForm.newsletter_type[0].focus();
		return false;
	}
	if(trim(elForm.subject.value)=='')
	{
		alert("Please enter subject.")
		elForm.subject.focus();
		return false;
	}
	if(trim(elForm.scheduled_date.value)=='')
	{
		alert("Please enter scheduled date.")
		elForm.scheduled_date.focus();
		return false;
	}
	if(trim(elForm.scheduled_time.value)=='')
	{
		alert("Please enter scheduled time.")
		elForm.scheduled_time.focus();
		return false;
	}
}

function ValidateMembershipNumbers()
{
	elForm = document.dataform;
	
	if(trim(elForm.membership_numbers.value)=='')
	{
		alert("Please enter membership numbers.")
		elForm.membership_numbers.focus();
		return false;
	}
	
}

function ValidateSpamProtruction()
{
	elForm = document.dataform;
	
	if(trim(elForm.normal_user.value)=='')
	{
		alert("Please enter normal users accessiblity.")
		elForm.normal_user.focus();
		return false;
	}
	if(isNaN(elForm.normal_user.value))
	{
		alert("Please enter normal users accessiblity in numeric.")
		elForm.normal_user.focus();
		return false;
	}
	if(trim(elForm.member.value)=='')
	{
		alert("Please enter members accessiblity.")
		elForm.member.focus();
		return false;
	}
	if(isNaN(elForm.member.value))
	{
		alert("Please enter members accessiblity in numeric.")
		elForm.member.focus();
		return false;
	}
	
}

function FillValueOnFocus(FieldId,FieldValue)
{
	//alert("Called");
	var Fid = document.getElementById(FieldId);

	if(Fid.value == FieldValue)
	{
		Fid.value = "";
	}
}

function FillValueOnBlur(FieldId,FieldValue,AjaxUrl,AjaxDivIdVal)
{
	var Fid = document.getElementById(FieldId);

	if(Fid.value == "")
	{
		Fid.value = FieldValue;
	}
	else
	{

		//AjaxUrl			= typeof(AjaxUrl) != 'undefined'?AjaxUrl+"?MobileNo="+Fid.value:"";

		AjaxUrl			= typeof(AjaxUrl) != 'undefined'?AjaxUrl:"";

		AjaxDivIdVal	= typeof(AjaxDivIdVal) != 'undefined'?AjaxDivIdVal:"";

		if(AjaxUrl != "")
		{
			CallAjax(AjaxUrl,AjaxDivIdVal,true);
		}
	}
	
}

function validatePassword()
{
	elForm = document.dataform
	var pw1 = elForm.newpassword.value;
	var pw2 = elForm.newpassword2.value;
	var minLength = 6; // Minimum length
	
	if(trim(elForm.oldpassword.value)=="")
	{
		alert("Please enter current password.")
		elForm.oldpassword.focus();
		return false;
	}
	
	if(trim(elForm.newpassword.value)=="")
	{
		alert("Please enter new password.")
		elForm.newpassword.focus();
		return false;
	}
	
	// check for minimum length
	if (elForm.newpassword.value.length < minLength)
	{
		alert('Your password must be at least ' + minLength + ' characters long. Try again.');
		elForm.newpassword.focus();
		return false;
	}
	
	if(trim(elForm.newpassword2.value)=="")
	{
		alert("Please enter your confirm password.")
		elForm.newpassword2.focus();
		return false;
	}
	
	if(pw1 != pw2)
    {
        alert('New password and confirm password do not match.');
        elForm.newpassword2.focus();
        return false;
    }
}

function fogetpassword()
{
	elForm = document.dataform;
	
	if(trim(elForm.email.value)=="")
	{
		alert("Please enter email address.")
		elForm.email.focus();
		return false;
	}
	if(!isEmail((elForm.email.value)))
    {
        alert('Please enter a valid email address.');
        elForm.email.focus();
        return false;
    }
}

function validateDeals()
{
	elForm = document.dataform;
	
	if(trim(elForm.coupon_code.value)=='')
	{
		alert("Please enter coupon code.")
		elForm.coupon_code.focus();
		return false;
	}
	
	if(trim(elForm.price.value)=='')
	{
		alert("Please enter save % or Rs.")
		elForm.price.focus();
		return false;
	}
	
	if(trim(elForm.url.value)=='')
	{
		alert("Please enter link.")
		elForm.url.focus();
		return false;
	}
	
	if(trim(elForm.date.value)=='')
	{
		alert("Please enter date.")
		elForm.date.focus();
		return false;
	}
}

function validateSearch()
{
	elForm = document.search_form;

	if( elForm.category.selectedIndex==0 && ((trim(elForm.search_text.value)=='') || (elForm.search_text.value=='Eg: Gift Store, Cannaught Place')))
	{
		alert("Please enter text to search or select category.")
		elForm.search_text.focus();
		return false;
	}
}

function validateUserSearch()
{
	elForm = document.searchbox;

	if(trim(elForm.searchtext.value)=='' || (elForm.searchtext.value=='Search'))
	{
		alert("Please enter text to search.")
		elForm.searchtext.focus();
		return false;
	}
}

function validateStaticPage()
{
	elForm = document.dataform
	
	if(trim(elForm.title.value) == '')
    {
        alert('Please enter title.');
        elForm.title.focus();
        return false;
    }
}

function validateAdminComment()
{
	elForm = document.dataform
	
	if(elForm.company_id.selectedIndex==0)
	{
		alert("Please select company.")
		elForm.company_id.focus();
		return false;
	}
}
