function validatFax(value,id){		
	if(value!='' && value.length != 10){
		alert("Mobile no. should be 10 digit");
		 $(id).focus();			
	}
}
function fillPincode(pincode,opt){
		//$(opt+':country_id').disabled=true;
                //Validation checks now using prototype validation
		if(pincode == '') { 
			//alert('Please enter a valid Zip/Postal Code') ;
			//$(opt+':postcode').focus();
		}else if(pincode.length!=6){
			//alert('Zip/Postal Code should be 6 digit') ; 
			//$(opt+':postcode').focus();
		}else if(isNaN(pincode)){
			//alert('Please enter a valid Zip/Postal Code') ; 
			//$(opt+':postcode').focus();
		}else {
			var params = 'zpincode=' + pincode ; 
			var myAjax = new Ajax.Request( 
				'/aramex_postcode.php',
				{ 
					method:'post', 
					parameters: params, 
					onComplete: function(ajaxReq) {
						eval(ajaxReq.responseText) ; 
						if(result.found) {
							$(opt+':city').value = result.location_name;
							
							for(i=0;i<document.getElementById(opt+':region_id').length;i++)
							{
								if(document.getElementById(opt+':region_id').options[i].value==result.state_code)
								{
									document.getElementById(opt+':region_id').selectedIndex=i
								}
							}
							jQuery(opt+'_country_id').value = $(opt+':country_id').value;
							jQuery(opt+'_region_id').value = $(opt+':region_id').value;							
							//billing.save();
							checkout.gotoSection('shipping_method');
						}
						else {
							//$(opt+':city').value = '' ; 
							//$(opt+':region').value = '' ;
							//alert('We do not deliver to this location currently') ; 
							$(opt+':city').focus();
						}
					}
				}
			);
		}
	}
/*--------------Function used in edit adders in user profile----*/	
function fillPinecodeEdit(pincode){	
	 if(pincode.length!=6 && pincode!=''){
		alert('Zip/Postal Code should be 6 digit') ; 
		$('zip').focus();
	}else {
		var params = 'zpincode=' + pincode ; 
		var myAjax = new Ajax.Request( 
			'/aramex_postcode.php',
			{ 
				method:'post', 
				parameters: params, 
				onComplete: function(ajaxReq) { 
					eval(ajaxReq.responseText) ;
					if(result.found) {
						$('city').value = result.location_name;							
						for(i=0;i<document.getElementById('region_id').length;i++){
							if(document.getElementById('region_id').options[i].value==result.state_code){
								document.getElementById('region_id').selectedIndex=i
							}
						}							
					}else{
						//$('city').value   = ''; 
						//$('region').value = '';						
					}
				}
			}
		);
	 }
  }
function telephoneValue(evt,value){	
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
	((evt.which) ? evt.which : 0));	
	if(charCode==8 )return true;
	
	/*if(charCode!=48 && value.length==''){	
		return false;		
	}*/
	if (charCode > 31 && (charCode < 48 || charCode > 57 ) && charCode!=45) {
	   return false;
	}
	return true;	
}
function validatString(evt){
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
	((evt.which) ? evt.which : 0));				
	if (charCode > 31 && (charCode > 48 || charCode < 57) && (charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 122) && charCode!=45 && charCode!=39 && charCode!=32) {
		return false;
	}
	return true;	
}
function setShippingValue(){
	$('shipping_country_id').value	= $('shipping:country_id').value
	$('shipping_region_id').value	= $('shipping:region_id').value
}

/**	function for login check before design submit	**/
function checkLogin()
{
	var posturl = '/profile/design/checklogin/';
	new Ajax.Request(posturl, {
		method: 'post',
		
		parameters: {},
		
		onComplete: function(transport) {				

			if(transport.responseText == 'true')
				setLocation('/contest/index/submitdesign');
			else
				jQuery.colorbox({inline:true, width:'670px', height:'490px',href:"#my_icheckout_modal_login_outer"});
		}
	});
}

function showErrorMsg()
{
	if($('my_icheckout_modal_login_message'))
	{
		$('my_icheckout_modal_login_message_content').update('Please Login to proceed');
		$('my_icheckout_modal_login_message').removeClassName('no-display');
	}
	else return false;
}


function setCookie(c_name,value,exdays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}


function cartItemRemoveMethod(id){

	var dataString = Form.serializeElements( $('cartmainform').getInputs('text') );
	var url = '/checkout/cart/delete/id/'+id;

	var ajaxRequest = new Ajax.Request(url, {
		method:       'post',
		parameters:   id,
		asynchronous: true,
		onComplete:   function() { showCart(); }
	});
        
	return false;
}

function cartUpdate()
{
	var dataString = Form.serializeElements( $('cartmainform').getInputs('text') );
	var url = '/checkout/cart/updatePost/';

	var ajaxRequest = new Ajax.Request(url, {
		method:       'post', 
		parameters:   dataString, 
		asynchronous: true,
		onComplete:   function() { showCart(); }
	});
}

function showCart()
{
     var reloadurlnext = '/ajax/index/cart/';

     new Ajax.Request(reloadurlnext, {
            method: 'post',
            //parameters: {'product_id': productId},
            onComplete: function(trans) {
                    document.getElementById('quickCartPopup').innerHTML = '';
                    document.getElementById('quickCartPopup').innerHTML = trans.responseText;
                    jQuery.colorbox({inline:true, width:'690px', onOpen: function(){ setTimeout("jQuery('#cboxClose').show();",500)}, onCleanup: function(){jQuery('#cboxClose').hide();},  height:'500px', href:"#quickCartPopup"});
            }
    });
}



//character limit for textarea
function countit(){
	formcontent=document.getElementById('about_me').value;
	  document.getElementById('displaycount').innerHTML= 255 - formcontent.length;		
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	countit();
	if (obj.getAttribute && obj.value.length>mlength)
		obj.value=obj.value.substring(0,mlength)
}

