//change the text below to reflect your own,
var before=""
var current=""
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[m-1]+" "+d+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday==0&&dhour==0&&dmin==0&&dsec==1){
document.getElementById('timer_span').innerHTML=current
return
}
else
document.getElementById('timer_span').innerHTML=dday+" days "+dhour+" hours "+dmin+" minutes  "+dsec+" seconds"
setTimeout("countdown(theyear,themonth,theday)",1000)
}


function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function add_commas(nStr)
      { 
      nStr += '';
      x = nStr.split('.');
      x1 = x[0];
      x2 = x.length > 1 ? '.' + x[1] : '';
      var rgx = /(\d+)(\d{3})/;
      while (rgx.test(x1)) {
      x1 = x1.replace(rgx, '$1' + ',' + '$2');
      }
      return x1 + x2;
      }






function addOption(selectbox,text,value)
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}


function ignoreIt()
{
	document.frmData.btnSave.focus();
	return false;
}

function bcheck(fd,msg,tab){
	if(msg == undefined){
		msg = '';
	}
// open a tab before alert
if(tab != undefined && $(tab).length){
	$(tab).click();
}
//alert(msg);
var res=trim(fd.value);
if(res=='') {
if(msg!=''){ 
alert(msg);
}
return true;              
}else{ 
return false;
}

}


function isdomain(dm,tab){

var str=dm.value;	
if(str!=''){
s=str.indexOf('http');

if(s>=0){
	// open a tab before alert
	if(tab != undefined && $(tab).length){
		$(tab).click();
	}
alert("Only domain name should be entered as Site Url\nPlease do not put http://");
dm.focus();
return true;
}

}


}




function chkstr(fd,fn,tab){

j=fd.value.length;
        ok = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ';
        for(i=0; i<j; i++){
        if (ok.indexOf(fd.value.charAt(i))<0){
                msg = fn+' can only consist of a-z, A-Z\n';
				// open a tab before alert
				if(tab != undefined && $(tab).length){
					$(tab).click();
				}
                alert(msg);
				fd.focus();  
				return true;  
                i=99;
        }
        }

}

function isValidEmail(email){
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
        return true;
    }else{
        return false;
    }
} 

function numstr(fd,fn,tab){

j=fd.value.length;
        ok = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890! ';
        for(i=0; i<j; i++){
        if (ok.indexOf(fd.value.charAt(i))<0){
                msg = fn+' can only consist of a-z, A-Z, 0-9\n';
				// open a tab before alert
				if(tab != undefined && $(tab).length){
					$(tab).click();
				}
                alert(msg);
				fd.focus();  
				return true;  
                i=99;
        }
        }

}



function chkalpha(fd,fn,tab){

j=fd.value.length;
        ok = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäåöšžäåöšžÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜŸäëïöüÿ,:;!@#$%^&*().&~\n\r-_$?=/\"\'‘  ';
        for(i=0; i<j; i++){
        if (ok.indexOf(fd.value.charAt(i))<0){
                msg = fn+' can only consist of alpha numeric characters\n';
                // open a tab before alert
				if(tab != undefined && $(tab).length){
					$(tab).click();
				}
				alert(msg);
				fd.focus();  
				return true;  
                i=99;
        }
        }

}


function chknum(fd,fn,tab){

j=fd.value.length;
        ok = '1234567890.-)(+ ';
        for(i=0; i<j; i++){
        if (ok.indexOf(fd.value.charAt(i))<0){
                msg = fn+' can only consist of numeric characters\n';
				// open a tab before alert
				if(tab != undefined && $(tab).length){
					$(tab).click();
				}
                alert(msg);
				fd.focus();  
				return true;  
                i=99;
        }
        }

}

function chkspace(fd,fn,tab){

j=fd.value.length;
        ok = '1234567890';
        for(i=0; i<j; i++){
        if (ok.indexOf(fd.value.charAt(i))<0){
                msg = fn+' can only consist of numeric characters\n';
				// open a tab before alert
				if(tab != undefined && $(tab).length){
					$(tab).click();
				}
                alert(msg);
				fd.focus();  
				return true;  
                i=99;
        }
        }

}

function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length;i>=0;i--)
{
selectbox.remove(i);
}
}

function DropDownSelect(obj, val)
	{
		var i;
		var len = obj.options.length;
		for (i=0; i<len; i++)
		{
			if (obj.options[i].value == val)
			{
				obj.selectedIndex = i;
				break;
			}
		}
	}
	
	
function isCreditCard(textObj) {
 /*
  *  This function validates a credit card entry.
  *  If the checksum is ok, the function returns true.
  */
   var ccNum;
   var odd = 1;
   var even = 2;
   var calcCard = 0;
   var calcs = 0;
   var ccNum2 = "";
   var aChar = '';
   var cc;
   var r;
   
   ccNum = textObj.value;
   for(var i = 0; i != ccNum.length; i++) {
      aChar = ccNum.substring(i,i+1);
      if(aChar == '-') {
         continue;
      }

      ccNum2 = ccNum2 + aChar;
   }
   
   cc = parseInt(ccNum2);
   if(cc == 0) {
      return false;
   }
   r = ccNum.length / 2;
   if(ccNum.length - (parseInt(r)*2) == 0) {
      odd = 2;
      even = 1;
   }
   
   for(var x = ccNum.length - 1; x > 0; x--) {
      r = x / 2;
      if(r < 1) {
         r++;
      }
      if(x - (parseInt(r) * 2) != 0) {
         calcs = (parseInt(ccNum.charAt(x - 1))) * odd;
      }
      else {
         calcs = (parseInt(ccNum.charAt(x - 1))) * even;
      }
      if(calcs >= 10) {
         calcs = calcs - 10 + 1;
      }
      calcCard = calcCard + calcs;
   }
   
   calcs = 10 - (calcCard % 10);
   if(calcs == 10) {
      calcs = 0;
   }
   
   if(calcs == (parseInt(ccNum.charAt(ccNum.length - 1)))) {
      return true;
   }
   else {
      return false;
   }
}



function isEmail (s) {
        //if (isEmpty(s))
    //   if (isEmail.arguments.length == 1) return defaultEmptyOK;
    //   else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    //if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i;
    var ok;
    var sLength = s.length;
    
//  ok = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_@.';
//      for(i=0; i<sLength; i++){
//      if (ok.indexOf(s.value.charAt(i))<0){
//              return false;
//      }
//      }
    i=1;
    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}







function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}

function checkEmailValid(emailStr,msg)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var errMsg="";   
	var matchArray=emailStr.match(emailPat)

	if (matchArray==null) 
	{
	   errMsg=errMsg+"The "+msg+" Email Address seems incorrect!";
	   return errMsg;
	}
	else
	{
	  var user=matchArray[1]
	  var domain=matchArray[2]
	  if (user.match(userPat)==null) 
	  {
		errMsg=errMsg+"The "+msg+" Email Address seems incorrect 111!";
		return errMsg;       
	  }
	  var IPArray=domain.match(ipDomainPat)
	  if (IPArray!=null) 
	  {
		  for (var i=1;i<=4;i++) 
			  {
			if (IPArray[i]>255) 
				{
				errMsg=errMsg+"The "+msg+" Email Address seems incorrect 222!";
				return errMsg;
				}//IF
			  }//for
	   }//IP Array
	   var domainArray=domain.match(domainPat)
	   if (domainArray==null) 
	   {
		 errMsg=errMsg+"The "+msg+" Email Address seems incorrect 333!";
		 return errMsg;
	   }
	   var atomPat=new RegExp(atom,"g")
	   var domArr=domain.match(atomPat)
	   var len=domArr.length
	   if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>6) 
	   {
		 errMsg=errMsg+"The "+msg+" Email Address seems incorrect 444!";
		 return errMsg;	
	   } 
	   if (len<2) 
	   {
		 errMsg=errMsg+"The "+msg+" Email Address seems incorrect 555!";
		 return errMsg;	 
	   } 
	 }//End  Match
	return "0";
}

function goUrl(loc)
	{
	document.location.href=loc;
	}
	
function notYet()
	{
	alert("Sorry this item is not available!")
	}


function WholeNumberOnly(opt,msg,tab)
{
	var pos=opt.value.indexOf(".")
	if  (pos>0)
	  {
		// open a tab before alert
		if(tab != undefined && $(tab).length){
			$(tab).click();
		}
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value=opt.value.substr(0,opt.value.length-1);
		opt.focus();
		return false;
	  }	 
	if  (isNaN(opt.value))
	  {
		// open a tab before alert
		if(tab != undefined && $(tab).length){
			$(tab).click();
		}
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value=opt.value.substr(0,opt.value.length-1);
		opt.focus();
		return false;
	  }
	  return true;
}

function WholeNumberOnlyEmpty(opt,msg,tab)
{
	var pos=opt.value.indexOf(".")
	if  (pos>0)
	  {
		// open a tab before alert
		if(tab != undefined && $(tab).length){
			$(tab).click();
		}
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value="";
		opt.focus();
	  }	 
	if  (isNaN(opt.value))
	  {
		// open a tab before alert
		if(tab != undefined && $(tab).length){
			$(tab).click();
		}
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value="";
		opt.focus();
	  }
}

function TinyIntOnly(opt,msg,tab)
{
	if(opt.value>255)
	{
		// open a tab before alert
		if(tab != undefined && $(tab).length){
			$(tab).click();
		}
		alert("The "+msg+" can not be greater than 255!");
		opt.value="";
		opt.focus();
	}
}

function NumericOnly(opt,msg,tab)
{
	if  (isNaN(opt.value))
	  {
		// open a tab before alert
		if(tab != undefined && $(tab).length){
			$(tab).click();
		}
		alert("The "+msg+" can only be numbers!"); 
		opt.value=opt.value.substr(0,opt.value.length-1);
		opt.focus();
	  }
}

function SetZero(opt)
{
	if  (opt.value=="")
	  {
		opt.value=0;
	  }
}

function SetBlank(opt)
{
	if  (opt.value=="0")
	  {
		opt.value="";
	  }
}


var http_request = false;
   function makePOSTRequest(url, parameters,st) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
          
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = eval('alertContents'+st);
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
   
var hh=0,hh2=0;
var inter,inter_val;


function Show_Box(div_id)
{

//Depending on the amount of text, set the maximum height here in pixels
obj = document.getElementById(div_id);

	if(hh2==132)
	{
	clearInterval(inter);
	return;
	}	

	obj.style.visibility = 'visible';
	hh2+=4;
	obj.style.height = hh2 + 'px';
}

//same way as above but reversed
function Hide_Box(div_id)
{
	obj = document.getElementById(div_id);

	if(hh2==4)
	{
	obj.style.visibility = 'hidden';
	obj.style.height = '0.1em';
	clearInterval(inter);
	return;
	}
	hh2-=4;
	obj.style.height = hh2 + 'px';
}



function ShowBox(div_id)
{

//Depending on the amount of text, set the maximum height here in pixels
obj = document.getElementById(div_id);

	if(hh==132)
	{
	clearInterval(inter_val);
	return;
	}	

	obj.style.visibility = 'visible';
	hh+=4;
	obj.style.height = hh + 'px';
}

//same way as above but reversed
function HideBox(div_id)
{
	obj = document.getElementById(div_id);

	if(hh==4)
	{
	obj.style.visibility = 'hidden';
	obj.style.height = '0.1em';
	clearInterval(inter_val);
	return;
	}
	hh-=4;
	obj.style.height = hh + 'px';
}



function show(div_id){
document.getElementById(div_id).style.display='';
}

function hide(div_id){
document.getElementById(div_id).style.display='none';
}

function getParentByTagName(obj, tagName) {
tagName = tagName.toLowerCase();
while (obj!= null && obj.tagName!=null && obj.tagName.toLowerCase() !=
tagName) {
obj=obj.parentNode;
}
return obj;
}

