// JavaScript Document

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function displaynews_sg(){
 document.write ('Société Générale: the winners of CITIZEN ACT are “inventing the bank of tomorrow” by educating children, providing rural micro-finance and setting up an online community for women    <span class="redtitles"> <a href="groupnews.htm" class="redtitles">more &gt;&gt; </a> </span>');
}

function displaynews_sggsc(){
 document.write ('Société Générale Global Solution Centre launches unique CSR initiative <br><br><b><img src="images/p_arrow.jpg" width="9" height="9" border="0"> <a href="news.htm" >more</b></a>');
}

function displaynews_sgsapit(){
 document.write ('Société Générale Global Solution Centre launches unique CSR initiative   <b><span class="redtitles"> <a href="news.htm" class="redtitles">more &gt;&gt; </a> </span>');
}


function displayjobs_sggsc(){
	 document.write ('<a href="http://careers.socgen.com/sggsc/en/home.html" target="_blank" ><img src="images/img_sggsc_careers.jpg" width="100" height="80" border="0" alt="Jobs in SG GSC" ><br>For exciting career perspectives, find out how a career at <br>SG GSC could be perfect for you...<b></a> ');

}

function groupsites(){
 document.write('<select name="sgroup" style="width:120" onchange="if(this.value.length > 0) window.open(this.value);">');
 document.write('<option value="" selected>SG Group Sites</option>');
 document.write('<option value="http://www.societegenerale.com/en?_force=1">SG Group</option>');
 document.write('<option value="http://www.sgcib.com">SGCIB</option>');
 document.write('</select>');
}


function openWindow(theURL,winName,features) { 
    var width = 400;
    var height = 300;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top + ", " + features;
    myWindow = window.open(theURL, winName, windowFeatures);
    myWindow.focus();
}


function openfullWindow(theURL,winName, width, height, features) { 
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top + ", " + features;
    myWindow = window.open(theURL, winName, windowFeatures);
    myWindow.focus();
}


// Example:

// writeCookie("myCookie", "my name", 24);

// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

// Example:

// alert( readCookie("myCookie") );

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function loginform()
{
  return "<table width='80%' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td>&nbsp;</td>      </tr>      <tr>        <td class='textSmall'>Login</td>      </tr>      <tr>        <td class='textSmall'><input name='textfield' type='text' class='textbox' size='15' maxlength='15'></td>      </tr>      <tr>        <td class='textSmall'>Password</td>      </tr>      <tr>        <td class='textSmall'><input name='textfield2' type='password' class='textbox' size='15' maxlength='15'></td>      </tr>      <tr>        <td align='left'><a href='../resources/default.htm'><img src='../images/button_login.jpg' width='52' height='16' vspace='4' border='0' ></a></td>      </tr>    </table>"	
}



//--------------------Job application validation
function nn_Key()
{

if ((event.keyCode<48) || (event.keyCode>57) )
event.keyCode = 0;
}

function chkFileFormat(entered,alertbox)
{
with (entered)
{
formatvalue=value.indexOf(".doc");
if(formatvalue==-1)
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
}

function enforcechar(what,limit){
if (what.value.length>=limit)
return false
}

function emailvalidation(entered, alertbox)
{
with (entered)
{
apos=value.indexOf("@"); 
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
}

function emptyvalidation(entered, alertbox)
{
with (entered)
{
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
function formvalidation(thisform)
{
with (thisform)
{
if (emptyvalidation(name,"Name is empty!")==false) {name.focus(); return false;};
if (document.form1.qual.value=="0") { alert("Please mention your qualification");qual.focus(); return false;} else{};
if (document.form1.qual.value=="Others") {if (emptyvalidation(qualothers,"Please mention your qualification!")==false) {qualothers.focus(); return false;}; } else{};
if (document.form1.skill1.value=="0") { alert("Please choose your Skillset 1");skill1.focus(); return false;} else{};
if (document.form1.skill1.value=="Others") {if (emptyvalidation(sklothers1,"Please mention your Skillset 1!")==false) {sklothers1.focus(); return false;}; } else{};
if (document.form1.skill2.value=="0") { alert("Please choose your Skillset 2");skill2.focus(); return false;} else{};
if (document.form1.skill2.value=="Others") {if (emptyvalidation(sklothers2,"Please mention your Skillset 2!")==false) {sklothers2.focus(); return false;}; } else{};
if (document.form1.skill3.value=="0") { alert("Please choose your Skillset 3");skill3.focus(); return false;} else{};
if (document.form1.skill3.value=="Others") {if (emptyvalidation(sklothers3,"Please mention your Skillset 3!")==false) {sklothers3.focus(); return false;}; } else{};
if (document.form1.expr.value=="0") { alert("Please mention your Experience!");expr.focus(); return false;} else{};

if (emptyvalidation(email,"Email field cannot be empty!")==false) {email.focus(); return false;};
if (emailvalidation(email,"Invalid Email ID.Please enter a proper Email!")==false) {email.focus(); return false;};
if (emptyvalidation(FILE1,"Attach your resume!")==false) {FILE1.focus(); return false;};
if (chkFileFormat(FILE1,"Invalid Format! Can attach only MS Word Documents")==false) {FILE1.focus(); return false;};
}
}

//--login validate

function submitform(){
    document.frmInput.action="login.asp";
	if (validatefrm())
	 document.frmInput.submit();
}

function validatefrm(){
var emsg="";

  un=document.frmInput.txtUser.value;
  pw=document.frmInput.txtPassword.value;
   emsg=blank_validate("User Name",un);
   emsg=emsg+blank_validate("Password",pw);
 
   if (emsg.length)
   {
     alert("Following fields are MANDATORY" + "\n\n"+emsg);
	 return false;
	}
	else
	 return true; 
}

function blank_validate(fldname,fldvalue){
if (fldvalue.length){
  if (isWhitespace(fldvalue))
   return "";
 }

  return fldname+"\n";
}

function isWhitespace(fldval){
 whitespace=" /t/n/r";
 var whiteschar=0;
 for (i=0;i< fldval.length;i++){
  var c = fldval.charAt(i);
   if (whitespace.indexOf(c) == 0)
     whiteschar=whiteschar+1;
 }

 if (fldval.length==whiteschar && whiteschar > 0)
   return false;
  else
   return true; 
}
