// Tobics Web Javascript Function Library.
// (C) 2008 - 2009 Invitation King

function GotoURL(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
}

function confirmdelete(locationval)
{
answer = confirm("Are You sure You wish to delete this item?")

if (answer !="0")
{
location = locationval
}
}

function confirmdelaction(locationval,msg)
{
answer = confirm(msg)

if (answer !="0")
{
location = locationval
}
}

function confirmaction(locationval,msg)
{
answer = confirm(msg)

if (answer !="0")
{
location = locationval
}
}

function confirmchoice(msg)
{
answer = confirm(msg)

if (answer !="0")
{ return true; } else { return false; }

}

function goto(locationval)
{
location = locationval
}

function popup(mylink, windowname,w,h,features)
{
<!-- 
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
mywnd=window.open(mylink, windowname, settings);

mywnd.focus()
-->
}
//popup window close when focus lost .... 
//mywnd.onblur=function(){self.close();};

function winclose() {
<!-- 
window.close();
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
} 
-->
}


//window close and follow link from opener 
function wincloselnk(linke) {
<!-- 
window.close();
if (window.opener && !window.opener.closed) {
//window.opener.location.reload();
window.opener.location.href=linke;
} 
-->
}


//isKeyIntLim , limit size of number
function isKeyIntLim(evt,instr,len)
<!-- 
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
			var str=instr.value
			var slen = str.length;

			if (charCode == 8) { instr.value=""; } //clear 

			if (slen>=len) { return false; }         
         
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
-->
		}
// Key Integer Numeric Test 
<!-- 
function isKeyInt(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
			
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
-->
		}
// Key floating Numeric Test 
function isKeyFloat(evt,instr)
{
         var charCode = (evt.which) ? evt.which : event.keyCode;
			var str=instr.value
			var slen = str.length;
			var i = 0;
			var cnt = 0;
			
					for (i=0;i<slen;i++)
					{
					var ccode = str.charCodeAt(i);
				
					if ( ccode == 46) { cnt ++;}	//if found in str then exit	
					}
					
			//if there is no other '.' then ok 
			  if (charCode ==  46 && cnt < 1) { return true; } 	
			//make sure then numeric keypresses are ok
         if (charCode > 31 && (charCode < 48 || charCode > 57))
           { return false; } 			
              return true;
}		

function formatnr(num,dec,thou,pnt,curr1,curr2,n1,n2) {
var x = Math.round(num * Math.pow(10,dec));
if (x >= 0) n1=n2='';
var y = (''+Math.abs(x)).split('');
var z = y.length - dec; 
if (z<0) z--; 
for(var i = z; i < 0; i++) y.unshift('0'); 
if (z<0) z = 1; y.splice(z, 0, pnt); if(y[0] == pnt) 
y.unshift('0'); while (z > 3) {z-=3; 
y.splice(z,0,thou);}
var r = curr1+n1+y.join('')+n2+curr2;
return r;
}

function changetext(idElement,text)
	{
	document.getElementById(idElement).innerHTML =text; 
	}

// function initialises the credit card exp box 
function initccexp(selbox)
{
<!--
var now = new Date();
var i;
var j;
var startmonth = now.getMonth() + 1;
var monthnumber = startmonth;
var year = now.getFullYear();
var tyear;
var tmonth;
var y3lim;
y3lim=12;
var tyear = year+'';
tmonth =""+monthnumber;

for (j=year; j<=year+4; j++)
{

		if (j > year+3 & monthnumber <= 1) {
			y3lim = startmonth;
		}

 	for(i=monthnumber; i<=y3lim; i++)
    	{
   		tyear =j+"";
			tmonth =i+"";
	
			if (tmonth.length<2){
			tmonth = "0"+i;
			}

    	 	seladdrow(selbox, tmonth +'/' + right(tyear,2) , tmonth +'/' + right(tyear,2) );
    	}
    	

monthnumber=1;
}
-->
}


function right(str, n){
     if (n <= 0)
        return "";
     else if (n > String(str).length)
        return str;
     else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
     }
 }


function seladdrow(theSel, newText, newValue)
{
<!--
  if (theSel.length == 0) {
    var newOpt1 = new Option(newText, newValue);
    theSel.options[0] = newOpt1;
    theSel.selectedIndex = 0;
  } else if (theSel.selectedIndex != -1) {
    var selText = new Array();
    var selValues = new Array();
    var selIsSel = new Array();
    var newCount = -1;
    var newSelected = -1;
    
    var i;
    for(i=0; i<theSel.length; i++)
    {
      newCount++;
      if (newCount == theSel.selectedIndex) {
        selText[newCount] = newText;
        selValues[newCount] = newValue;
        selIsSel[newCount] = false;
        newCount++;
        newSelected = newCount;
      }
      selText[newCount] = theSel.options[i].text;
      selValues[newCount] = theSel.options[i].value;
      selIsSel[newCount] = theSel.options[i].selected;
    }
    for(i=0; i<=newCount; i++)
    {
      var newOpt = new Option(selText[i], selValues[i]);
      theSel.options[i] = newOpt;
      theSel.options[i].selected = selIsSel[i];
    }
  }
-->
}


//validate email
function validate_email(field) {
<!--
with (field)
 {
 var str=field.value;
 var filter=/^.+@.+\..{2,3}$/

 if (filter.test(str)) {  return true; }
  else {  alert("Please valid email address!")
   	 	return false;
		 }

 }
-->
}

function validate_required(field,alerttxt) {
<!--
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false;}
else {return true}
}
-->
}

function validate_checkbox(field,alerttxt) {
<!--
with (field)
{
if (!checked)
  {alert(alerttxt);return false;}
else {return true}
}
-->
}

function validate_dropdown(field,alerttxt) {
<!--

if (field.selectedIndex<=0)
  {alert(alerttxt);return false;}
else {return true}

-->
}

function validate_cc(field,flen,alerttxt) {
<!--
with (field)
{
if (value==null||value==""||value.length<flen)
  {alert(alerttxt);return false;}
else {return true}
}
-->
}


function validate_pw(field1,field2,alerttxt) {
<!--
var fld=field1.value
if (fld!=field2.value||fld==""||fld.length<6)
 {alert(alerttxt);return false;}
else {return true}
-->
}

function validate_date(instr,alerttxt) {
<!--
var str=instr.value
var a=str.substring(3,5);
var b=str.substring(0,2);
//alert (a);
//alert (b);
if (a>12) { alert("Month Greater than 12 !!"); return false; }
if (b>31) { alert("Day Greater than 31 !!"); return false; }
if (str.substring(2,3)!="-"||str.substring(5,6)!="-"||str.length!=10||a>12||b>31)
 {alert(alerttxt);return false;}
else {return true}

//-->
}

function isLeap(theYear) {
if (theYear % 400 == 0) return true;
if (theYear % 100 == 0) return false;
if (theYear % 4 == 0) return true;
return false;
}
