// email.js

var UN='undefined';
var LO=window.location.protocol=="file:";
var errColor='#ffdddd';
var okColor='#ffffff';
var emailformok=false;
var DN='webtransformer.com';
var DB=false;
var WW=0;WH=0;gWX();

function dN(n){
	return eval('(typeof('+n+')!=UN);')
}

function vN(n){
	if(dN(n)){
		var v=String(eval('('+n+');'));
		if(v=="")v="[Null]";
		return v;
	}else{
		return "[Undefined]";
	}
}

function nW(w,n,f){
	win=window.open(w,n,f,false);
}

function fD(date){
  var base=new Date(0);
  var skew=base.getTime();
  if (skew>0)date.setTime(date.getTime()-skew);
}

function aDB(s){
	if(DB||LOCAL)alert(s);
}

function sP(id,pr,v){
	document.getElementById(id).setAttribute(pr,v);
}

function sCL(id,v){
	sP(id,"class",v);
	sP(id,"className",v);
}

function gWX() {
	if(typeof( window.innerWidth ) == 'number' ) {
		WW = window.innerWidth;
		WH = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ){
		WW = document.documentElement.clientWidth;
		WH = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		WW = document.body.clientWidth;
		WH = document.body.clientHeight;
	}
}

// column sizing and layout

function cR(){
// create list of column objects
  var oc=0;
  for(i=1;i<9;i++){
    cn="Column"+i;
    c=document.getElementById(cn);
    if(c)oc++;
  }
  if(oc==0)return;
// determine how many columns to fill, column width, avg. column height
  w=gW("WhiteSpace")-1;
  w=Math.floor(w*0.98);
  nc=Math.floor(w/235);
  if (nc<1)nc=1;
  if(nc>oc)nc=oc;
  cw=Math.floor(w/nc);
  if(cw<150)cw=150;
  cp=1/nc;
// set each column's width, margin, border, padding
  mw=5;
  pw=5;
  cw-=2*mw+2*pw;
  cwpx=cw+"px";
  mwpx=mw+"px";
  pwpx=pw+"px";
  for(i=1;i<9;i++){
    cn="Column"+i;
    if(document.getElementById(cn)){
      setStyleById(cn,"width",cwpx);
      setStyleById(cn,"margin",mwpx);
      setStyleById(cn,"padding-left",pwpx);
      setStyleById(cn,"padding-right",pwpx);
    }
  }
// find each vertically scrollable object, get height, determine cummulative height
  divs=document.getElementsByTagName("div");sdivs=[];sdivsh=[];sdivsp=[];ns=0;sdt=0;
  for(i=0;i<divs.length;i++)
  {
    if(divs[i].id=="Scrollable"){
      sdivs[ns]=divs[i];
      sdt+=sdivsh[ns++]=divs[i].offsetHeight;
    }
  }
  if(ns>0){
// calculate each vertically scrollable object's height as a percent of cummulative height
    for(i=0;i<ns;i++)
      sdivsp[i]=(sdt>0)?(sdivsh[i]/sdt):(1/ns);
// for each column to fill, move scrollable objects into column
    tp=0; // percentage of cummulative height allocated so far
    si=0; // index number of scrollable object to use
    for(ci=1;ci<=nc;ci++){ // loop through columns
      cn="Column"+ci;c=document.getElementById(cn); // current column object to fill
      c.appendChild(sdivs[si]); // column must have at least one element
      tp+=sdivsp[si++];
      ms=ns-(nc-ci); // first scrollable object that must be reserved for next column
      while(((tp+0.5*sdivsp[si])<(ci*cp))&&(si<ms)){ // add scrollable objects to current column
        c.appendChild(sdivs[si]);
        tp+=sdivsp[si++];
      }
    }
// move any remaining scrollable objects to last column
    while(si<ns){
      c.appendChild(sdivs[si]);
      tp+=sdivsp[si++];
    }
  }
  return nc;
}

function gW(n){
  if(n.length>0)return document.getElementById(n).offsetWidth;
  if(typeof(window.innerWidth)=='number')return window.innerWidth;
  if(document.documentElement&&document.documentElement.clientWidth)return document.documentElement.clientWidth;
  if(document.body&&document.body.clientWidth)return document.body.clientWidth;
  return 0;
}

function gH(n){
  if(n.length>0)return document.getElementById(n).offsetHeight;
  if(typeof(window.innerWidth)=='number')return window.innerHeight;
  if(document.documentElement&&document.documentElement.clientHeight)return document.documentElement.clientHeight;
  if(document.body&&document.body.clientHeight)return document.body.clientHeight;
  return 0;
}

function oH(o){
  o.offsetHeight;
}

// cookie

function pC(nm,v,d){
	path='/';
	secure=0;
	expires=0;
	if (d){
		expires=new Date();
		fD(expires);
		expires.setTime(expires.getTime()+d*24*60*60*1000);
	}
	document.cookie=nm+"="+escape(v)+((expires)?"; expires="+expires.toGMTString():"")+((path)?"; path="+path:"")+((DN)?"; DN="+DN:"")+((secure)?"; secure":"");
}

function sC(nm,v){
	pC(nm,v,0);
}

function xC(nm){
	path='/';
	if(gC(nm))document.cookie=nm+"="+((path)?"; path="+path:"")+((DN)?";DN="+DN:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function gC(nm){
	var dc=document.cookie;
	var prefix=nm+"=";
	var begin=dc.indexOf("; "+prefix);
	if(begin==-1){
		begin=dc.indexOf(prefix);
		if(begin!=0)return "";
	}else{
		begin+=2;
	}
	var end=document.cookie.indexOf(";",begin);
	if(end==-1)end=dc.length;
	return unescape(dc.substring(begin+prefix.length,end));
}

// date

function fD(date){
  var base=new Date(0);
  var skew=base.getTime();
  if (skew>0)date.setTime(date.getTime()-skew);
}

function y2k(n){
	return (n<1000)?n+1900:n;
}

function gdD(n){
	var Days=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	return Days[n];
}

function gmD(n){
	var Months=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	return Months[n];
}

function dsD(d){
	var sf="th";
	switch (d.getDate()){
case 1:
case 21:
case 31:
		sf="st";
		break;
case 2:
case 22:
		sf="nd";
		break;
case 3:
case 23:
		sf="rd";
		break;
	}
	return gmD(d.getMonth())+" "+d.getDate()+sf+", "+y2k(d.getYear());
}

function wkD(){
	var d=new Date();
	var t=d.getTime();
	var wd=d.getDay();
	var df=(wd==0)?1:((wd<6)?(1-wd):2);
	var d1=new Date(t+df*24*3600000);
	var d2=new Date(t+df*24*3600000+4*24*60*60*1000);
	ds1=dsD(d1);
	ds2=dsD(d2);
	ys1=ds1.substring(ds1.indexOf(",")+2,ds1.length);
	ys2=ds2.substring(ds2.indexOf(",")+2,ds2.length);
	ds1a=ds1.substring(0,ds1.indexOf(","));
	if(ys1!=ys2)
	{
		rs=ds1+" - "+ds2;
	}
	else
	{
		ms1=ds1.substring(0,ds1.indexOf(" "));
		ms2=ds2.substring(0,ds2.indexOf(" "));
		if(ms1!=ms2)
			ds1b=ds2.substring(0,ds2.indexOf(","))
		else
			 ds1b=ds2.substring(ds2.indexOf(" ")+1,ds2.indexOf(","));
		rs=ds1a+" - "+ds1b+", "+ys1;
	}
	return rs;
}

// email


function vF(){
	emailformok=true;
	rF(document.getElementById("FromName"),"Please enter your name.","NameErr");
	vE(document.getElementById("FromEmail"),"Please enter your email ID.","EmailErr");
	rF(document.getElementById("FromMessage"),"Please enter a message.","MessageErr");
	if(emailformok!=true)return false;
	return true;
}

function rF(v,err,msg){
	if(v.value==null||v.value==""){
		v.style.backgroundColor=errColor;
		document.getElementById(msg).firstChild.nodeValue=err;
		if(emailformok)v.focus();
		emailformok=false;
		return false;
	}else{
		v.style.backgroundColor=okColor;
		document.getElementById(msg).firstChild.nodeValue=" ";
		return true;
	}
}

function vE(v,err,msg){
	if(!peF(v.value)){
		v.style.backgroundColor=errColor;
		document.getElementById(msg).firstChild.nodeValue=err;
		if(emailformok)v.focus();
		emailformok=false;
		return false;
	}else{
		v.style.backgroundColor=okColor;
		document.getElementById(msg).firstChild.nodeValue=" ";
		return true;
	}
}

function peF(id){
	var v=1;
	var tld=1;
	var doms=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var idp=/^(.+)@(.+)$/;
	var sp="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var spp="\[^\\s"+sp+"\]";
	var unm="(\"[^\"]*\")";
	var ipp=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var a=spp+'+';var wd="("+a+"|"+unm+")";
	var up=new RegExp("^"+wd+"(\\."+wd+")*$");
	var domp=new RegExp("^"+a+"(\\."+a +")*$");
	var mat=id.match(idp);
	if(mat==null)return false;
	var u=mat[1];
	var dom=mat[2];
	for(i=0;i<u.length;i++)
		if(u.charCodeAt(i)>127)return false;
	for(i=0;i<dom.length;i++)
		if(dom.charCodeAt(i)>127)return false;
	if(u.match(up)==null)return false;
	var ipary=dom.match(ipp);
	if(ipary!=null)
	{
		for(var i=1;i<=4;i++)
			if(ipary[i]>255)return false;
	}
	var ap=new RegExp("^"+a+"$");
	var dary=dom.split(".");
	var len=dary.length;
	for(i=0;i<len;i++)
		if(dary[i].search(ap)==-1)return false;
	if(tld && dary[dary.length-1].length!=2 && dary[dary.length-1].search(doms)==-1)return false;
	if(len<2)return false;
	return true;
}

