var banner = new Array();
banner[0]="flash_image_1.gif"
banner[1]="flash_image_2.gif"
banner[2]="flash_image_3.gif"
banner[3]="flash_image_4.gif"
banner[4]="flash_image_5.gif"
banner[5]="flash_image_6.gif"
var i=0;
var rotateVar=0;
sMsg = "Field cannot be left blank";
sAlphaMsg="Field can accept only alphabets"
sPwdMsg="password under four characters is not allowed";
sPwdMismatch = "Your passwords did not match; try retyping them";
sValCode = "Enter the image code"
sTerms = "You cannot register until you accept our Terms of Service and Privacy Policy.";
sCountryMsg="Please Select Country Code"
sStateMsg="Please Select State"
sNumberMsg="Field can be only numbers"
sPhoneNumber="Invalid Number"
sZero="Value cannot be zero"
sAlphaNumericMsg="Field can accept alphanumeric"
spaceMsg="Password field should not contain space";
sPhoneNumberLength="Phone Number should have 10 char long";
sEmailMsg="Invalid Email Id";
sLoginIdSpaceMsg="Login Id should not contain space";
iFlag=1;
sValue="Invalid "
/*For checking email Address*/
function emailCheck(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		if (str.indexOf(at)==-1){
		   document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return 0;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return 0;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return 0;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return 0;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return 0;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return 0;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return 0;
		 }

 		return 1;
	}
	function eCheck(str){

	var at="@"
	var dot="."
	var underscr="_"
	var lat=str.indexOf(at)
	var lunderscr=str.indexOf(underscr)
	var lstr=str.length
	var ldot=str.indexOf(dot)	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 )
	{
		     return false
	}	
	if(true==isInteger(str.charAt(0)+""))
	{
		     return false
	}
	
	if (str.indexOf(underscr)==0 )
	{
		     return false
	}
	if (str.substring(lunderscr+1,lstr).match(/_/)!=null)
	{
		     return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0)
	{
		     return false
	}
	if (str.indexOf(at,(lat+1))!=-1)
	{
		     return false
	}
	if (str.charAt(lstr-1)==dot)
	{
		     return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		     return false
    }
	if (str.substring(ldot-1,ldot)==dot || str.substring(ldot+1,ldot+2)==underscr)
	{
		     return false
    }
	if (str.substring(ldot-1,ldot)==underscr || str.substring(ldot+1,ldot+2)==dot)
	{
		     return false
    }
	
    if (str.substring(lat-1,lat)==underscr || str.substring(lat+1,lat+2)==underscr)
	{
	             return false
	}
        if (str.substring(lat,lstr).match(/(_)/)!=null)
	{
		     return false
	}
	var regexp = /(\.)/
	str.match(regexp)
	var b=str.indexOf(RegExp.$1)
	if((str.substring(b+1,b+2).match(regexp))!=null)
	{
		     return false;
	}	
	var b =str.substring(lstr,lstr-4)
	var regexp = /([0-9])/
	if(b.match(regexp)!=null)
	{
		     return false
	}
	if (str.indexOf(dot,(lat+2))==-1)
	{
		    return false
	}
	if (str.indexOf(" ")!=-1)
	 {
		    return false
	 }
	var regexp = /([!#$%^&*({|`~+=}\-)?'":;<>,\/\/\[\\\]]+)/
	if(str.match(regexp)!=null)
	{
	            return false
	}
    return true;
}
/*function eCheck(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		if (str.indexOf(at)==-1){
		   //document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		  //  document.getElementById("errEmailId").innerHTML="<span class='err_txt1'>Invalid E-mail ID</span>";
		   return false;
		 }

 		return true;
	}
*/
/*For checking street Address*/
function streetCheck(address)
{

       // var regexp = /([\\!$%^+&*|=({`~})?_@'";<>\[\]]+)/
	    var regexp = /([\\!$%^+&*|={`~}?_@;<>\[\]]+)/
	if(address.match(regexp)!=null)
	{
		return false
	}
	var regexp = /([_\-\/.,'"):]+)/
	if(((address.charAt(0)+"").match(regexp))!=null)
	{
		return false;
	}
	if(address.match(/(#)/))
	{
		var b=address.indexOf(RegExp.$1)
		if(b==0)
		{
			if((address.substring(b+1,b+2).match(/[a-z|A-Z]+/))!=null )
			{
			     return false;
			}
		}
		else
		{
			if((address.substring(b+1,b+2).match(/[a-z|A-Z]+/))!=null || (address.substring(b,b-1).match(/[0-9]+/))!=null )
			{
			     return false;
			}
		}
		if (address.substring(b+1,address.length).match(/(#)/))
		{
		        return false
		}
	}
	if(address.match(/(\/)/))
	{
		var b=address.indexOf(RegExp.$1)
		if((address.substring(b+1,b+2).match(/[a-z|A-Z]+/))!=null || (address.substring(b,b-1).match(/[a-z|A-Z]+/))!=null )
		{
		     return false;
		}
		if (address.substring(b+1,address.length).match(/(\/)/))
		{
		     return false
		}
	}
	if(address.match(/(:)/))
	{
		var b=address.indexOf(RegExp.$1)
		if((address.substring(b+1,b+2).match(/[a-z|A-Z]+/))!=null || (address.substring(b,b-1).match(/[0-9]+/))!=null )
		{
		     return false;
		}
		if (address.substring(b+1,address.length).match(/(:)/))
		{
	     		return false
		}
	}
	//For not Repeating
	var regexp = /(\-)/
	address.match(regexp)
	var b=address.indexOf(RegExp.$1)
	if (address.substring(b+1,address.length).match(regexp))
	{
	     return false
	}
	// For not to display Continuosly
	var regexp = /([_\-\/.,:#]+)/
	address.match(regexp)
	var b=address.indexOf(RegExp.$1)
	if((address.substring(b+1,b+2).match(regexp))!=null)
	{
		return false;
	}
	 return true;
}

/*Global Method*/
function isInteger(val){
 	if (isBlank(val)){return false;}
 	for(var i=0;i<val.length;i++)
 	   {
 	   if(!isDigit(val.charAt(i))){return false;}
           }
 	   return true;
}
function isDigit(num) {
 	if (num.length>1){return false;}
 	var string="1234567890";
 	if (string.indexOf(num)!=-1){return true;}
 	return false;
}

function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++)
	   {
		   if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	   }
	   return true;
}

function isFloat(value) {
		arr=value.split('.');
		if(arr.length>=3){return false;}
		if(isInteger(value)==false ){
            return value.length>0 && !(/[^0-9.]/).test(value) && (/\.\d/).test(value);
        }else{
        return true;
        }
}


/*Introducing Banner*/
function rotateImage()
{
if(rotateVar==(banner.length-1))
rotateVar=0
else
rotateVar++;
document.getElementById('imageRotate').src="../jsp/nri_images/"+banner[rotateVar]
timeMsg();
}

$(document).ready(function() {
initialize();    
setTimeout("rotateImage()",5000)   
});

function timeMsg()
{
setTimeout("rotateImage()",5000)
}

/*For Maintaining Key Press Handler*/
function enterKeyPressHandler(e,cnt_name) {// To handle Enter Key has TAB
var key = window.event ? e.keyCode : e.which;
	if(key==13 ){
		if(cnt_name=="submit"){
			valForm();
		}else if(cnt_name=="updateProfile"){
			updateUser();	
		}
		else if(cnt_name=="payment_submit"){
			processOrder();	
		}if(cnt_name=="yellow"){
			submitYellowPagesEntry();
		}if(cnt_name=="classified"){
			submitClassifiedEntry();
		}if(cnt_name=="edityellow"){
			var conId=document.getElementById("hiddenContentId").value;
			editYellowPageEntry(conId);
		}if(cnt_name=="editclassified"){
			var conId=document.getElementById("hiddenYellowContentId").value;						
			editClassifiedEntry(conId);
		}else {
		document.getElementById(cnt_name).focus(); // Focusing Corrosponding Control
		}
	}
}
/*Function for checking isAlpha*/
function isalpha(val){
	var regexp = /([!#$%^&*=(+\-.{`~})?_@|'":;<>,\\\/\[\]0-9]+)/
	if(val.match(regexp)!=null){
		return false;
	}
    return true;
}

/* Change sub navigation in web communities */
function changeNavigation(val) {
	$("#"+val).attr("class","locallnk1");
}

	/**Text Area Limit Validation**/	
function checkTxtAreaLmt(obj,maxlen) {
	var aa=document.getElementById(obj.id).value;
	if (aa.length > maxlen) // if too long...trim it!
	document.getElementById(obj.id).value = document.getElementById(obj.id).value.substring(0, maxlen);
//	document.getElementById(errId).innerHTML= "*Left: "+parseInt(maxlen-aa.length);
}

function checkTxtAreaLimit(obj,maxlen,errId) {
	var aa=document.getElementById(obj.id).value;
	if (aa.length > maxlen) // if too long...trim it!
	document.getElementById(obj.id).value = document.getElementById(obj.id).value.substring(0, maxlen);
        if(document.getElementById(errId)){
		document.getElementById(errId).innerHTML= "*Left: "+parseInt(maxlen-aa.length);
	} else {
		document.getElementById(errId.id).innerHTML= "*Left: "+parseInt(maxlen-aa.length);
	}
	
}
	
		/**Clear Error Msg from classifieds and Yellow Pages**/
function clearValidation()
{
document.getElementById("errTitle").innerHTML="";
document.getElementById("errTag").innerHTML="";
document.getElementById("errCountry").innerHTML="";
document.getElementById("errState").innerHTML="";
document.getElementById("errCity").innerHTML="";
document.getElementById("errPhoneNumber").innerHTML="";
document.getElementById("errMail").innerHTML="";
document.getElementById("errWebSite").innerHTML="";
document.getElementById("errDescription").innerHTML="";
document.getElementById("errMetroCity").innerHTML="";
}

function setPhone(e,id){
	var ph=document.getElementById(id).value;
	var charCode = window.event ? e.keyCode : e.which;
	
	if (charCode > 31 && (charCode < 48 || charCode > 57)) 
	{
	return false;
	}
	else {
		if(charCode!=8){
		if(ph.length==3)
		{
		ph=ph+"-";
		document.getElementById(id).value=ph;
		}
		if(ph.length==7)
		{
		ph=ph+"-";
		document.getElementById(id).value=ph;
		}
		}
	}
}   
    /*For NRI Cities*/
    var yellowpage="yellow"
    var classified="classified"
    var events="events.htm"
    var cities="cities"
    
    /*For NRI communities*/
    var blog="blog"
    var survey="survey"
    var ebooks="ebook"
    var forum="forum"
    var gcard="greet"
    
    
    /*NRI Communication*/
    var accountsummary="account-summary.htm"
    var usagehistory="usage-history.htm";
    var downloads="download.htm";
    var orderhistory="order-history.htm";
	var ratesheet="rate-sheet.htm";
	var product="communication-home.htm";
    
    var cururl=location.href;            
function initialize(){    
        if(cururl.indexOf(cururl.match(yellowpage))!=-1){    
        document.getElementById('yellowpage_navigation').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(classified))!=-1){
        document.getElementById('classified_navigation').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(events))!=-1){	
        document.getElementById('event_navigation').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(cities))!=-1){	
        document.getElementById('cities_navigation').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(blog))!=-1){
        document.getElementById('blognavigation').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(survey))!=-1){
        document.getElementById('surveynavigation').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(ebooks))!=-1){
        document.getElementById('nebook').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(forum))!=-1){
        document.getElementById('nforum').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(gcard))!=-1){
        document.getElementById('ngreet').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(accountsummary))!=-1){
        document.getElementById('naccountsummary').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(usagehistory))!=-1){
        document.getElementById('nusagehistory').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(downloads))!=-1){
       document.getElementById('ndownloads').className="locallnkIn"
        }else if(cururl.indexOf(cururl.match(orderhistory))!=-1){
			if(document.getElementById('norderhistory')) {
		       document.getElementById('norderhistory').className="locallnkIn"
			}
        }else if(cururl.indexOf(cururl.match(ratesheet))!=-1){
       document.getElementById('nratesheet').className="locallnkIn"
		}else if(cururl.indexOf(cururl.match(product))!=-1){
       document.getElementById('nproduct').className="locallnkIn"
		}
		
     } 
	 
/*is AlphaNumeric*/	 
function isAlphaNumeric(val){
	var regexp = /([!#$%^&*=(+\-.{`~})?_@|'":;<>,\\\/\[\]]+)/
	if(val.match(regexp)!=null){
		return false;
	}
    return true;
}
/*post to url*/
function post_to_url(path, params, method) {
    method = method || "post"; // Set method to post by default, if not specified.
    
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);

    for(var key in params) {  
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);
        form.appendChild(hiddenField);
    }
    document.body.appendChild(form);    
    form.submit();
}
	
	function clearText(id){
		document.getElementById(id).innerHTML="";
	}
	
	function checkForSpace(val){
		
		var sss=val;
		var count=sss.indexOf(" ");
		if(count==-1){
			return false;
		}
		else{
			return true;
		}
		
	}
	
	function checkPhoneNumberFormat(value){
       var phone=value;
       var j=0;
        if(phone.length<12){
        return false;
        }else if(phone.charAt(3)!='-' || phone.charAt(7)!='-' ){
        return false;
        }else{
                for(i=0;i<phone.length;i++){
                if(phone.charAt(i)=='-'){
                j++;
                }
                }
                if(j>2){
                        return false;
                }
        }
        return true;
   }
   
   function doWordWrap(){
	if (window.attachEvent == undefined) { 
				var tag1 = document.getElementsByTagName("span");
				for (var i = 0; i < tag1.length; i++) 
				{
				if (tag1.item(i).className == "wordwrap") 
				{
				var text1 = tag1.item(i).innerHTML; 
				tag1.item(i).innerHTML = text1.replace(/(.*?)/g, "<wbr />"); 
				}
				}
	} 

}

function doWordWraps(className){
	if (window.attachEvent == undefined) { 
				var tag1 = document.getElementsByTagName("span");
				for (var i = 0; i < tag1.length; i++) 
				{
				if (tag1.item(i).className == className) 
				{
				var text1 = tag1.item(i).innerHTML; 
				tag1.item(i).innerHTML = text1.replace(/(.*?)/g, "<wbr />"); 
				}
				}
	} 

}

function dontAllowPreviousDate()
{
    //alert('datepic');
	var dates=$("#datepic").val(); 
	if(dates!="" && dates!=null){
     var enddate =dates.split("-");
		 var newendDate=new Date(enddate[0]+'/'+enddate[1]+'/'+enddate[2]);
		 var d = new Date();
 		 var month = d.getMonth();
		 month++;
		 var today = new Date(d.getFullYear()+'/'+month+'/'+d.getDate());
		 if(newendDate>=today) {
			  $("#serr").html("");
		 } else {
			 $("#serr").html("Shedule Date should be greater than today");
			  document.getElementById('datepic').value='';
		 }
	}
    /*var chosenDate=document.getElementById('datepic').value
    var curDate=new Date();
    var today=curDate.getFullYear()+"-"+(curDate.getMonth()+1)+"-"+curDate.getDate();
    if(chosenDate<=today) {
        alert('Date should be greater than today');
        document.getElementById('datepic').value='';
    }*/
}
var album="album.htm";
function navi_nriservices(typeVal) {
	if(typeVal=='Mug' || typeVal=='T-Shirt' || typeVal=='Photo Print') {
		document.getElementById('naviproducts').className="locallnkIn";	
	}else{
		if(cururl.indexOf(cururl.match(album))!=-1){
			document.getElementById('navimanagealbums').className="locallnkIn";	
		}else if(cururl.indexOf(cururl.match(orderhistory))!=-1||cururl.indexOf(cururl.match(orderhistory))!=-1){
			document.getElementById('naviorderhistory').className="locallnkIn";	
		}else{
                        document.getElementById('naviproducts').className="locallnkIn";
                }
	}
}
function hidePrevNext(count,pos,interval,prevId,nextId){    
    if(pos!=0&&pos+interval>=count) {
        //Unhide prev
        //Hide next
        $("#"+prevId).css("display","inline"); 
	$("#"+nextId).css("display","none");         
    }else if(pos==0&&pos+interval>=count) {
        //Hide both
        $("#"+prevId).css("display","none"); 
	$("#"+nextId).css("display","none");         
    }else if(pos==0&&pos+interval<count) {
        //Hide Prev
        //Unhide next
        $("#"+prevId).css("display","none"); 
	$("#"+nextId).css("display","inline");         
    }else if(pos!=0&&pos+interval<count) {
        //Unhide Both
        $("#"+prevId).css("display","inline"); 
	$("#"+nextId).css("display","inline");         
    }
}
function keyPressIsAlphaNumeric(evt)
{
	var charCode = window.event ? evt.keyCode : evt.which; 
	var val=String.fromCharCode(charCode);
	var regexp = /([!#$%^&*=(+\-.{`~})?_@|'":;<>,\\\/\[\]]+)/
	if(val.match(regexp)!=null || charCode==32)
	{return false;}
    return true;
}

function chkAlphaOrNumber(evt,id){
        var charCode = window.event ? evt.keyCode : evt.which;
        if((id=="landValue") || (id=="minArea") || (id=="landPostalCode") || (id=="saleValue") || (id=="sellerPostalCode") || (id=="landArea") || (id=="phoneNumber") || (id=="postalCode") || (id=="age")) {
                if ((charCode >= 48 && charCode <= 57) || charCode==0 || charCode==8)
                        {return true;}
                        else
                        {return false;}
        }
		if((id=="sellerName") || (id=="name") || (id=="ownerName") || (id=="locality")) {
			if (charCode==32){
				var sample=document.getElementById(id).value;
                if(sample.length==0){
                   return false;
                }
               return true;
            }
			if((charCode >= 65 && charCode <= 90)|| (charCode >= 97 && charCode <= 122) || charCode==0 || charCode==8 || charCode==46) {
				return true;
			} else {
				return false;
			}
		}
        if((id=="cityName") || (id=="cityCode1") || (id=="cityCode")){
			if (charCode==32){
				var sample=document.getElementById(id).value;
                if(sample.length==0){
                   return false;
                }
               return true;
            }
            if ((charCode >= 65 && charCode <= 90)|| (charCode >= 97 && charCode <= 122) || charCode==0 || charCode==8) {
				return true;
			}
            else {
				return false;
			}
        }

}
