
//Script By Pawan Kamboj on 10 Apr 08.

var sHTML="";
sHTML = sHTML+ '<style type="text/css"> .input_box {border:1px solid #cccccc; font-family:Arial, Helvetica, sans-serif; font-size:12px;}.star {color: #FF0000}</style>';
sHTML = sHTML+ '<div id="divInfoForm" style="width:1px; height:1px; visibility:hidden; position:absolute;z-index:99999; border:0px solid red;">';
sHTML = sHTML+ '	<table width="537" border="0" cellspacing="0" cellpadding="0" style=" font-size:12px; font-family:Arial, Helvetica, sans-serif;">';
sHTML = sHTML+ '	<tr>';
sHTML = sHTML+ '			<td width="98%"  onmousedown="dragStart(event, \'divInfoForm\')" height="35" style="background:url(images/hd-bg.gif); color:#fff; padding-left:12px; font-size:12px; font-family:Arial, Helvetica, sans-serif;cursor:move;"><strong>Please enter your details to register your interest and receive our career newsletter.</strong></td>';
sHTML = sHTML+ '			<td width="2%"><img src="images/close.gif" title="Close" onclick="HideMe();" style="cursor:pointer;" width="33" height="35" border="0" /></td>';
sHTML = sHTML+ '	</tr>';
sHTML = sHTML+ '	<tr>';
sHTML = sHTML+ '		<td height="283" width="100%" valign="top" colspan="2" style="background:url(images/cont-bg.jpg); color:#333; font-size:12px; font-family:Arial, Helvetica, sans-serif; cursor:default;">';
sHTML = sHTML+ '			<div id="divMiddleContents" style="margin:0px; padding:0px; width:100%;">';
sHTML = sHTML+ '			<table width="480" align="center" border="0" cellspacing="6" cellpadding="0">';
sHTML = sHTML+ '				<tr>';
sHTML = sHTML+ '				 	 <td>';
sHTML = sHTML+ '				 	 <iframe src="/eclipsewi/candidate/registercv/registercv_front.aspx" width="500" FRAMEBORDER="0" height="270" scrolling="No" id="testiframe2"></iframe> ';
sHTML = sHTML+ '				 	 </td>';
sHTML = sHTML+ '				 </tr>';
sHTML = sHTML+ '			</table>';
sHTML = sHTML+ '			</div>';
sHTML = sHTML+ '		</td>';
sHTML = sHTML+ '	</tr>';
sHTML = sHTML+ '</table>';
sHTML = sHTML+ '	</div>';

document.write(sHTML)


var divInfoForm = document.getElementById("divInfoForm");
var sInfoHTML=divInfoForm.innerHTML;

function CheckInfo()
{
	if(IsShowCMLORInfoWin())
	{
		ShowInfoForm();
	}
	else
	{
		divInfoForm.innerHTML="";
	}
}



function ShowInfoForm()
{
	
	//Code to handle the Flash Activation Code.
	if(document.getElementById("Content_Mid_Right"))
	{
		var sFLash='<object type="application/x-shockwave-flash" data="/_swf/banners.swf" width="100%" height="120"><param name="movie" value="/_swf/banners.swf" /><param name="wmode" value="transparent" /><img src="/images/noflash.jpg" alt="no flash" /></object>';
		//alert(document.getElementById("Content_Mid_Right").innerHTML);
		document.getElementById("Content_Mid_Right").innerHTML=sFLash;
	}
	
	// Calculdate browser's available width and height.
	var winW = window.screen.width
	var winH = window.screen.height;
	
	if (parseInt(navigator.appVersion)>3)
	{
		if (navigator.appName=="Netscape") 
		{
			winW = window.innerWidth; 
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) 
		{
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	
	var Height=320;
	var Width=537;
	var myTop=(winH/2)-Height/2;
	var myLeft=(winW/2)-Width/2;
	
	// If Top is -ve then fix at least 50
	if(myTop<50)
	{
		myTop=50
	}
	else if(myTop>200)
	{
		myTop=150
	}
	
	
	// If Left is -ve then fix at least 50
	if(myLeft<50)
	{
		myLeft=50
	}
	
	if(divInfoForm)
	{
		with(divInfoForm.style)
		{
			visibility="visible";
			position="absolute";
			height=Height + "px";
			width=Width + "px";
			top=myTop + "px";
			left=myLeft + "px";
		}
		divInfoForm.innerHTML=sInfoHTML;
	}
}

function HideMe()
{
	if(divInfoForm)
	{
		with(divInfoForm.style)
		{
			visibility="hidden";height="1px";width="1px";
		}
	}
}




function IsShowCMLORInfoWin()
{
	var bShowInfoWin=false;
	var sCookieName="FillInfoForm";
	
	
	
	if(!GetCookie(sCookieName))
	{
	
//		var expDate = new Date (); // pre-set to the current time and date
//		expDate.setTime(expDate.getTime() + 1000 * 60 * 60 * 24); // it should be expire after 24 hours
//		//expDate.setTime(expDate.getTime() + 1000 * 20); // it should be expire after 24 hours
//		CreateCookie("FillInfoForm", "CMLORInfoForm", expDate)
		
		bShowInfoWin=true;
	}	
	
	return bShowInfoWin;
}

function CreateCookie(name, value, expires)
{
		if (!expires) expires = new Date(); 
		document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}


function GetCookie(name)
{
	
	
//	var nameEQ = name + "=";
//	var ca = document.cookie.split(';');
//	for(var i=0;i < ca.length;i++) {
//		var c = ca[i];
//		while (c.charAt(0)==' ') c = c.substring(1,c.length);
//		if (c.indexOf(nameEQ) == 0)return c.substring(nameEQ.length,c.length);
//	}
//	return false; // If the cookie not found! or it has been expired.
	
	
	var cookies = document.cookie;
	if (cookies.indexOf(name) != -1)
	{
		var startpos = cookies.indexOf(name)+name.length+1;
		var endpos = cookies.indexOf(";",startpos)-1;
		if (endpos == -2) endpos = cookies.length;
		return unescape(cookies.substring(startpos,endpos));
	}
	else
	{
		return false; // If the cookie not found! or it has been expired.
	}
}

function DeleteCookie(name) {
	CreateCookie(name,"",-1);
}


function SendInformation()
{
	
	var sMessage="";
	var sTitle="", sName="", sCountry="", sEmail="", sPhone="", sInterest="", sQual="",sYearsExp="", sAttachment="", sRandomNumber="", sCode="";
	
	
	var ddTitle=document.getElementById("ddInfoTitle");
	var ddExperience=document.getElementById ("ddlExperience");
	var ddCountry=document.getElementById("ddInfoCountry");
	var radio=document.getElementsByName("chkInfoInterest");
	
	sCode="7" + "6" + "8" + "9";
	sTitle=ddTitle.options[ddTitle.options.selectedIndex].value;
	sName=document.getElementById("txtInfoName").value;
	sCountry=ddCountry.options[ddCountry.options.selectedIndex].text;
	sEmail=document.getElementById("txtInfoEmail").value;
	sPhone=document.getElementById("txtInfoPhone").value;
	sQual=document.getElementById("txtQualification").value;
	sYearsExp=ddExperience.options[ddExperience.options.selectedIndex].value;
	sAttachment = document.getElementById("hfDocument").value;
	
	sRandomNumber= sCode + Math.random();
	sRandomNumber = sRandomNumber.substr(0,(sRandomNumber.length)-4)
	sRandomNumber = sRandomNumber + sCode 
	
	if(radio.length>0)
	{
		var i;
		for(i=0;i<radio.length;i++)
		{
			if(radio[i].checked)
			{
				if(sInterest.length>0)
					sInterest= sInterest + ", " + radio[i].value;
				else
					sInterest= radio[i].value;
			}
		}
	}
	else
	{
		if(radio.checked)
			sInterest=radio.value;	
	}
	
	
	if(sTitle.replace(/ /gi,"").length==0)
	{
		ShowCommonMessage();
		ddTitle.focus();
		return;
	}
	if(sName.replace(/ /gi,"").length==0)
	{
		ShowCommonMessage();
		document.getElementById("txtInfoName").focus();
		return;
	}
	if(sCountry.replace(/ /gi,"").length==0 || sCountry.replace(/ /gi,"").toLowerCase()=="select")
	{
		ShowCommonMessage();
		ddCountry.focus();
		return;
	}
	if(!validateEmailv2(sEmail.replace(/ /gi,"")))
	{
		ShowErrormMessage("Please enter a valid email address !!");
		document.getElementById("txtInfoEmail").focus();
		return;
	}
	if(sPhone.replace(/ /gi,"").length==0)
	{
		ShowCommonMessage();
		document.getElementById("txtInfoPhone").focus();
		return;
	}
	
	if(sInterest.replace(/ /gi,"").length==0)
	{
		ShowCommonMessage();
		if(radio.length>0)
			radio[0].focus();
		else
			radio.focus()
		return;
	}
	
	if(sQual.replace(/ /gi,"").length==0)
	{
		ShowCommonMessage();
		document.getElementById("txtQualification").focus();
		return;
	}
	if(sYearsExp.replace(/ /gi,"").length==0)
	{
		ShowCommonMessage();
		ddExperience.focus();
		return;
	}
	
	
	//// If everything is OK then submit information
	
	var sURL="http://www.cmlor.com/SendInfo.asp?title=" + escape(sTitle) + "&name=" + escape(sName)+ "&country="+ escape(sCountry) + "&email=" + escape(sEmail) + "&phone=" + escape(sPhone) + "&interest=" + escape(sInterest)+ "&qualification=" + escape(sQual)+ "&experience=" + escape(sYearsExp) + "&section=home" + "&attachment=" + sAttachment + "&rnd=" + sRandomNumber;
	
	if(document.getElementById("imgSubmit"))
	{	
		document.getElementById("imgSubmit").disabled=true;
	}
	
	
	//ShowSuccessMessageAndHideBox();
	
	SendRequest(sURL);
}


function ShowCommonMessage()
{
	var divError = document.getElementById("divErrorMsg")
	var sCommonMessage="Please fill all the required field marked with '*' before submit."
	if(divError)
	{
		divError.innerHTML=sCommonMessage;
	}
	else
	{
		alert(sCommonMessage);
	}
}

function ShowErrormMessage(sMessage)
{
	var divError = document.getElementById("divErrorMsg")
	if(divError)
	{
		divError.innerHTML=sMessage;
	}
	else
	{
		alert(sCommonMessage);
	}
}

function HideErrorMessage(event)
{
	if (event.keyCode != 13)
	{
		var divError = document.getElementById("divErrorMsg")
		var sCommonMessage=""
		if(divError)
		{
			divError.innerHTML=sCommonMessage;
		}
	}
}

function SetAttachment(obj)
{
	var sInteresst = obj.value.toLowerCase();
	
	var divAttchment_1 = document.getElementById("divAttchment_1");
	var divAttchment_2 = document.getElementById("divAttchment_2");
	var hfDocument = document.getElementById("hfDocument");
	var chkInfoInterest_2 = document.getElementById("chkInfoInterest_2");
	
	
	if(sInteresst=="legal")
	{
		if(divAttchment_2.innerHTML.replace(/ /gi,"").length==0)
		{
			divAttchment_1.innerHTML = 'Attach CV below (If any)';
			divAttchment_2.innerHTML ='<iframe src="http://www.cmlor.com/UploadDocument.asp" frameborder="0" scrolling="no" style="width:100%; height:22px; margin:0px 0px 0px 0px; padding:0px 0px 0px; border:none; vertical-align:middle;" marginheight="0" marginwidth="0"></iframe>';
			
			//For testing purpose
			//divAttchment_2.innerHTML ='<iframe src="http://pawank/pumma/cmlor/UploadDocument.asp" frameborder="0" scrolling="no" style="width:100%; height:22px; margin:0px 0px 0px 0px; padding:0px 0px 0px; border:none; vertical-align:middle;" marginheight="0" marginwidth="0"></iframe>';
		}
	}
	else
	{
		if(hfDocument.value.indexOf(".")>0)
		{
			alert("Please remove attachment first!!");
			chkInfoInterest_2.checked=true;
			return false;
		}
		else
		{
			divAttchment_1.innerHTML = "";
			divAttchment_2.innerHTML ="";
		}
	}
	
}


var http_request = false; 

function SendRequest(url) 
{


///////// Code to enable the javascript permission for Firefox but need not enable as its working fine now.
////	try 
////	{
////		if(navigator.appName.toLowerCase()=="netscape")
////		{
////			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
////		}
////	}
////	catch (e) 
////	{
////		alert(e.message);
////		alert("Oops!!\r\n\r\nCan't send your information. Please check your browser settings!");
////	}


       if (window.XMLHttpRequest) { // Mozilla, Safari,...
           http_request = new XMLHttpRequest();
       } else if (window.ActiveXObject) { // IE
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
       }
       http_request.onreadystatechange = ShowResponse;
       http_request.open('GET', url, true);
       http_request.send(null);

} 

function ShowResponse() 
{

       if (http_request.readyState == 4) 
       {
           if (http_request.status == 200) 
           {
               //alert(http_request.responseText);
               
				var expDate = new Date (); // pre-set to the current time and date
				expDate.setTime(expDate.getTime() + 1000 * 60 * 60 * 24); // it should be expire after 24 hours
				CreateCookie("FillInfoForm", "CMLORInfoForm", expDate)
				
				/////alert("Your information has been submitted successfully. Thank you.");
				////HideMe();
				
				// Show message in the same box and hide the box after few seconds.
				ShowSuccessMessageAndHideBox()
               
           }
           else 
           {
               alert(http_request.status);
               alert("Oops!!\r\n\r\nCan't send your information. Please try later!!");
           }
       }

}

function ShowSuccessMessageAndHideBox()
{
	var divMiddleContents = document.getElementById("divMiddleContents")

	if(divMiddleContents)
	{
		divMiddleContents.innerHTML='<div style="border:0px solid green; font-size:15px; color:#006FAD; height:150px; width:97%; text-align:center;padding-top:80px; margin:0px 5px 0px 5px;"><b>Your information has been submitted successfully.<br><br>Thank you.</b><div>';
	}
	else
	{
		alert("Your information has been submitted successfully. Thank you.");
	}
	window.setTimeout("HideMe()",3000);
}

   

function validateEmailv2(email)
{
    if(email.length <= 0)
	{
	  return false;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
   return false;
}

function DoEnter(event)
{
  if (event.keyCode == 13)
  {
	SendInformation();
	return false;
  }
}

function HandleResize()
{
	if(divInfoForm.style.visibility=="visible")
	{
		ShowInfoForm();
	}
}




////window.onload=CheckInfo;
//////CheckInfo();

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

addEvent(window, 'load', CheckInfo);
addEvent(window, 'resize', HandleResize);



//////////////////////////
//// FLASH OBJECT FIX FUNCTIONS
//////////////////////////


function FlashIeFix()
	{ 
	if(isIE())
		{   
		var theObject = document.getElementById("Content_Mid_Right");    
		var theCode = theObject.innerHTML;    
		//theCode = theCode.substring(4 ,9+theCode.indexOf("</object>"))    
		document.write(theCode);  
		}
	}
function isIE()
	{  
// only for Win IE 6+  
// But not in Windows 98, Me, NT 4.0, 2000  
	var strBrwsr= navigator.userAgent.toLowerCase();  
	if(strBrwsr.indexOf("msie") > -1 && strBrwsr.indexOf("mac") < 0)
	{   
		if(parseInt(strBrwsr.charAt(strBrwsr.indexOf("msie")+5)) < 6)
		{     
		return false;    
		}    
		if(strBrwsr.indexOf("win98") > -1 ||       
					strBrwsr.indexOf("win 9x 4.90") > -1 ||       
					strBrwsr.indexOf("winnt4.0") > -1 ||      
					strBrwsr.indexOf("windows nt 5.0") > -1)    
			{     
			return false;    
			}    
		return true;  
		}
	else
		{    
		return false;  
		}
	}


///////////////////////
///////////////////////








//////////////////////////////////////////////////////
////////////////// Drag-Drop Functions



function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 1000;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}









///////////////////////////////////////////////////////
//////////////////////////////////////////////////////
