// JScript source code
var currentSection;

/************** Top menu image changes ******************************/
  function MenuImageClick(arg)
  {
    var td = document.getElementById('menu' + arg);
    td.className = 'click';
    var loc = String(arg);
    setTimeout('move(\'' + arg + '\')', 500);
  }
  
  function MenuImageMouseOver(arg)
  {
      if (currentSection != arg )
      { 
        var td = document.getElementById('menu' + arg);
        td.className = 'roll';
      }
  }
  
  
  function MenuImageMouseOut(arg)
  {
      if (currentSection != arg )
      { 
        var td = document.getElementById('menu' + arg);
        td.className = 'initial';
      }
  }
  
  function move(arg)
  {
    parent.location = arg + '.aspx';
  }
  
  function movehtml(arg)
  {
    parent.location = arg;
  }
 
 
/*******************************************************************/

/**************** Side menu text color change **********************/ 
  
  function sideMenuOver(arg)
  {
      var td = document.getElementById('sideMenu' + arg);
      td.className = 'sidemenuOver';
  }
  
  function sideMenuOut(arg)
   {
      var td = document.getElementById('sideMenu' + arg);
      td.className = 'sidemenuOff';
  }
  
 /****************************************************************/
 
 
 /******   Javscript to change/fade client logos every 5sec ******/
 var current = '1'; 
  
  function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 5;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

//change the opacity for different browsers
function changeOpac(opacity, id) 
{
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = 'alpha(opacity=' + opacity + ')';
}

function ImageChange()
{
	var imageId1 = 'imgBottom';	
	var imageId2 = 'imgTop';
	var mainimage1 = document.getElementById('imgBottom');
	var mainimage2 = document.getElementById('imgTop');

	
	var id = Number(current);
	//increment id but limit to 5 pics
	id = id + 1
	if (id > 25)
		id = 1;
	//set global current number
	var old = current;
	current = String(id);
	mainimage1.src = mainimage2.src;
	//hide the top image
	mainimage2.style.display = 'none';
	mainimage2.src = 'Images/ClientLogos/logo' + current + '.png';
 	//make top image transparent
	setOpacity(mainimage2, 0);
	//display top image
	mainimage2.style.display = "block";
	//fade in top image
	fadeIn(imageId2,0);

}

function Initialise()
{
    setCurrentSection('Home');
	intervalTimerId = setInterval("ImageChange()",5000);	
}

function setCurrentSection(section)
{
    if (currentSection == null)
        currentSection = 'Home';
    else
        currentSection = section;    
}

//window.onload = Initialise;
/***************************************************/

/*** Literature Section ***/


function openDoc(arg)
{
    window.open(arg);
}

/**************************/

function setMenuOn(arg)
{
    setCurrentSection(arg);
    var td = document.getElementById('menu' + arg);
    td.className = 'current';
}

function openWindow(address, width, height)
{
 
    window.open(address,'mywin','left=200, top=200, width=' + width + ', height=' + height + ',toolbar=0, resizable=0, location=0, menubar=0');
}

function expandImage(alt, address, width, height)
{
    var expand = document.getElementById('expand');
    var imgexpand = document.getElementById('imgExpand');
    
    imgexpand.src = address;
    imgexpand.alt = alt;
    
    expand.style.display = 'block';
    
    var h = parseInt(height);
    h = h/2;
    var w = parseInt(width);
    w = w/2;
    
    expand.style.marginTop = '-' + h + 'px';
    expand.style.marginLeft = '-' + w + 'px';
}

function closeExpand()
{
    var expand = document.getElementById('expand');
    expand.style.display = 'none';
}



// DEMO FORM VALIDATION

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateDemoEmail(arg){
	var emailID= document.getElementById(arg);
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }


// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
    var bracket=3;
    strPhone=trim(strPhone);
    if(strPhone.indexOf("+")>1) return false;
if(strPhone.indexOf("-")!=-1)bracket=bracket+1;
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false;
var brchr=strPhone.indexOf("(");
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false;
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false;
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateDemoPhone(arg){
	var Phone=document.getElementById(arg);
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number");
		Phone.focus();
		return false;
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number");
		Phone.value="";
		Phone.focus();
		return false;
	}
	return true;
 }
