function FComma(SS) {
	var T = "", S = String(SS), L = S.length - 1, C, j, P = S.indexOf(".") - 1;
	if (P < 0) 
		P = L;
	for (j = 0; j <= L; j++) {
		T += (C = S.charAt(j));
		if ((j < P) && ((P - j) % 3 == 0) && (C != "-")) 
		T += ",";
	}
	T="$"+T;
	return T;
}

function FDate(y,m,d)
{
	mm=String(m);
	dd=String(d);
	yy=String(y);
	if(m<10)
		mm='0'+m;
	if(d<10)
		dd='0'+d;
	date = yy+"-"+mm+"-"+dd;
	//date=mm+"-"+dd+"-"+yy;
	return date;
}
	
function FCommaNoDollor(SS) {
	var T = "", S = String(SS), L = S.length - 1, C, j, P = S.indexOf(".") - 1;
	if (P < 0) 
		P = L;
	for (j = 0; j <= L; j++) {
		T += (C = S.charAt(j));
		if ((j < P) && ((P - j) % 3 == 0) && (C != "-")) 
		T += ",";
	}
	
	return T;
}
//*************************************
// Methods for custom pricing feature
//*************************************
	function upsTrackingTerms(trackingID) 
	{ 
		var wndLeft = (screen.width - 600) / 2;
    	var wndTop = (screen.height - 300) / 2;
    	var url = "ups-tracking-terms-and-conditions.do?tID=" + trackingID;
    	window.open(url, 'UPS', "title='UPS Tracking', height=300, width=600,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,top=" + wndTop + ",left=" + wndLeft);

		return;
	} 
	function OpenNew(trgt)
	{
		window.open(trgt,"","width=650,height=610,resizable=0,scrollbars=1,menubar=no,top=8,left=125");
	}
	function qtycheck()
	{
		//alert("gere");
	     var qty=document.priceForm.quantity.value;
			if(qty <1){
			alert("A minimum quantity of 1 is required");
			document.priceForm.quantity.value="1";
			
			return false;
			}
	}
	function quantcheck() {		
		var str=document.getElementById("quantity").value;
		if(str <=0){
			alert("A minimum quantity of 1 is required");
			document.getElementById("quantity").value="1";
			return false;
			}		
 		 return true					
	}		
	function echeck()
	 {  
	     var price=String(document.priceForm.unitPrice.value);
	     var totalprice=document.priceForm.total.value;
	     var qty=document.priceForm.quantity.value;
	     var newTotal= price*qty;
	     var paymentType = document.priceForm.paymentMethod .value;
	     var usedSubscribes = document.priceForm.usedSubscribes.value;
	     if((paymentType != null) && (newTotal > totalprice) && paymentType.indexOf("Credit Card") != -1 ){
				alert("Total Price exceeds the Original Price.");
				document.priceForm.quantity.focus();
				return false;
	     }  
	     if(price <1 ){
				alert("Invalid Unit price");
				document.priceForm.unitPrice.focus();
				return false;
        }                      
         
	    if(qty <1){
			alert("A minimum quantity of 1 is required");
			document.priceForm.quantity.value="1";
		    return false;
		}
		
		if( checkDate(document.priceForm.startDate.value,"Start date") == false){
			
			return false;
			}
		
		if(	checkDate(document.priceForm.endDate.value,"End date") == false)
			return false;
		
		if(compareDates(document.priceForm.startDate.value,document.priceForm.endDate.value) == false){
              alert("Start Date should not be greater than or equals to the End date");
              document.priceForm.endDate.focus();
              return false;
        }
         
        if(document.priceForm.subscribers.value < document.priceForm.usedSubscribes.value){
              alert("No of Subscribers is less than the number currently being used!");
              document.priceForm.subscribers.value=document.priceForm.usedSubscribes.value;
              document.priceForm.subscribers.focus();
              return false;
        }
         return true;					
	}

   function compareDates (value1, value2) {
       var date1, date2;
	   var month1, month2;
	   var year1, year2;
	   var startDate = new Date; 
	   var endDate = new Date; 
	   year1 = value1.substring (0, value1.indexOf ("-"));
	   month1 = value1.substring (value1.indexOf ("-")+1, value1.lastIndexOf ("-"));
	   date1 = value1.substring (value1.lastIndexOf ("-")+1, value1.length);

	   year2 = value2.substring (0, value2.indexOf ("-"));
	   month2 = value2.substring (value2.indexOf ("-")+1, value2.lastIndexOf ("-"));
	   date2 = value2.substring (value2.lastIndexOf ("-")+1, value2.length);
	   startDate.setDate(date1);
       startDate.setMonth(month1-1); 
       startDate.setFullYear(year1); 
	   endDate.setDate(date2);
       endDate.setMonth(month2-1);
       endDate.setFullYear(year2);
	   if (startDate >= endDate) 
			return false
	   else 
		   return true;

	   /*if (year1 > year2) return false;
	   else if (year1 < year2) return true;
	   else if (month1 > month2) return false;
	   else if (month1 < month2) return true;
	   else if (date1 > date2) return false;
	   else if (date1 < date2) return true;
	   return true;*/
  } 

	function checkDate(getDate,display)
	{     
		 var beginDate = getDate;
		 var bDate = beginDate.split("-");
		 if(bDate.length<3 || bDate.length>3)
		  {
			  alert("Please check the date format[yyyy-mm-dd]");
			  return false;
		  }
		 if(bDate.length=3)
		 {
  			  var bYear = bDate[0];
			  var bMonth =  bDate[1];
			  var bDay = bDate[2];
			 			  
			  if (isNaN(bMonth)|| bMonth > 12 || bMonth <1)
			  {
				   alert("Please check the date format of "+display); 
				   return false;
			  }
			  if (isNaN(bDay) || bDay > 31 || bDay < 1) 
			  {
				   alert("Please check the date format of "+display);
				   return false;
			  }
			  if (isNaN(bYear) || bYear.length>4 || bYear.length< 4) 
			  {
				   alert("Please check the date format of "+display);
				   return false;
			  }
			  return true;
		 }
	}
	function onlyDecimal(e) 
	{
		var elem;
		var key;
		var keychar;
		
		//allow digits or decimal point
		var reg = /[\d\.]/;
	
		if(window.event) 
		{
			// for IE, e.keyCode or window.event.keyCode can be used
			key = e.keyCode;
			elem = e.srcElement;
		}
		else if(e.which) 
		{
			// netscape
			key = e.which; 
			
		}
		else 
		{
			// no event, so pass through
			return true;
		}
		if(key == 8 )
			return true;
		
		keychar = String.fromCharCode(key);
		
		//if the character fails, return false
		if (!reg.test(keychar))
			return false;
		
		//if we have the element, and the new char is a decimal point
		//block the point if there is already a decimal point
		if (keychar == ".")	
		{
			//var curStr = elem.value;
			return false;
		}

		//ok
		return true;
	}
	function allowDecimal(e) {
            var elem;
            var key;
            var keychar;
            //allow digits or decimal point
            var reg = /[\d\.]/;
            if(window.event) {
                        // for IE, e.keyCode or window.event.keyCode can be used
                        key = e.keyCode;
                        elem = e.srcElement;
            }
            else if(e.which) {
                        // netscape
                        key = e.which; 
            }
            else {
                        // no event, so pass through
                        return true;
            }
            keychar = String.fromCharCode(key);
            //if the character fails, return false
            if (!reg.test(keychar))
                        return false;
            //if we have the element, and the new char is a decimal point
            //block the point if there is already a decimal point
            if (null!=elem && keychar == ".") {
                        var curStr = elem.value;
                        return ( curStr.indexOf( "." ) == -1 );
            }
            //ok
            return true;
	}

	function goodchars(e,goods)
	{
		var key, keychar;
		//alert(e);
		key = getkey(e);
		if (key == null) return true;
		
		// get character
		keychar = String.fromCharCode(key);
		keychar = keychar.toLowerCase();
		goods = goods.toLowerCase();
		
		// check goodkeys
		if (goods.indexOf(keychar) != -1)
			return true;
		
		// control keys
		if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		   return true;
		
		// else return false
		return false;
	}
	function getkey(e)
	{
		if (window.event)
		   return window.event.keyCode;
		else if (e)
		   return e.which;
		else
		   return null;
	}

function getImgPos(i,which) {
    iPos = 0;
    while (i!=null) {
      iPos += i["offset" + which];
      i = i.offsetParent;
    }
    return iPos;
  }
  
  function toggleLayer(){
    vImg = document.images[arguments[0]];
    vLayer = document.getElementById(arguments[1]);
    vMode = arguments[2];    
    vLayer.style.left = getImgPos(vImg,"Left")+ 20 +"px";
    vLayer.style.top = getImgPos(vImg,"Top") + "px";
    if(vMode=="show"){
      vLayer.style.visibility = "visible";
    }else{
      vLayer.style.visibility = "hidden";
    }
  }

 function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
 
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}	
	


