var AJAX = new Object();
var url_follow_after_signon="";
var newUser_form_state=false;
var valid_uname=true;
var UserIn=false;
function OpenLink(URL,target)
{
if(URL=="")
 {
  
 }else{
  if(target==""){target="_self";}
  window.open(URL,target);
 }
}
function OpenSilentURL(URL)
{
window.open(URL,"shem_silent_frame");
}

AJAX=function()
{
var ro;
var browser = navigator.appName;
if(window.XMLHttpRequest)
 {
 ro=new XMLHttpRequest()
 }else if(window.ActiveXObject)
 {
  try
  {
  ro=new ActiveXObject("Msxml2.XMLHttp");
  }
  catch (e){
  try
  {
  ro=new ActiveXObject("Microsoft.XMLHttp");
  }
  catch (e) {}
  }
 }
return ro
}
var old_class;
var old_value;
function Active_field(fld)
{
eval("val=document.frmMain."+fld)
old_class=val.className
if(old_class=="left_textbox_blank")
 {
 eval("old_value_"+fld+"=val.value");
 eval("old_class_"+fld+"=val.className");
 
 if(fld=="txtPassword")
  {
  changeInputType(val,"password","Password","Password","")
  }
 if(fld=="txtRePassword")
  {
  changeInputType(val,"password","Retype Password","Retype Password","")
  }
 val.className="left_textbox"
 val.value=""
 }
}

function DeActive_field(fld)
{
eval("val=document.frmMain."+fld)
if(val.value=="")
 {
 val.className=eval("old_class_"+fld);
 val.value=eval("old_value_"+fld);
 if(val.name=="txtPassword" || val.name=="txtRePassword")
  {
  changeInputType(val,"text","","Password","")
  }
  
 }else{
 ValidateData(fld);
 }
}

var Uname_AJAX;
function ValidateData(fld)
{
//alert(fld)
errObj=document.getElementById("errMsg_"+fld)
if(errObj)
 {
 eval("val=document.frmMain."+fld)
 val=val.value
  if(fld=="txtUserName")
  {
   if(CheckValidData(val)==false)
    {
    errObj.innerHTML="Invalid Username";return;
    }else{
    if(val.length > 25) {errObj.innerHTML="Username too Big...";return;}
    errObj.innerHTML="";
    Uname_AJAX= new AJAX()
    CheckUsernameDB(val);
    }
  }
  
  if(fld=="FirstName")
  {
   if(CheckValidData(val)==false)
    {
    errObj.innerHTML="Invalid First Name";return;
    }else{
    if(val.length > 25) {errObj.innerHTML="First Name too Big...";return;}
    errObj.innerHTML="";
    //Uname_AJAX= new AJAX()
    //CheckUsernameDB(val);
    newUser_form_state=true;
    }
  }
  
  if(fld=="LastName")
  {
   if(CheckValidData(val)==false)
    {
    errObj.innerHTML="Invalid Last Name";return;
    }else{
    if(val.length > 25) {errObj.innerHTML="Last Name too Big...";return;}
    errObj.innerHTML="";
   // Uname_AJAX= new AJAX()
    //CheckUsernameDB(val);
    newUser_form_state=true;
    }
  }

  
  if(fld=="SecAnswer")
  {
   if(CheckValidData(val)==false)
    {
    errObj.innerHTML="Sepcial Characters not allowed";newUser_form_state=false;return;
    }else{
    if(val.length > 12) {errObj.innerHTML="Answer too Big...";newUser_form_state=false;return;}
    errObj.innerHTML="";
    newUser_form_state=true;
    }
  }
  
  if(fld=="EmailID")
  {
   if(checkValidateEmail(val)==false)
    {
    errObj.innerHTML="Invalid Email ID";newUser_form_state=false;return;
    }else{
    errObj.innerHTML="";
    newUser_form_state=true;
    }
  }
  

 
 }else{

 }
}

function CheckUsernameDB(str)
{
Uname_AJAX.abort();
Uname_AJAX.open('post','usercheck.asp');
Uname_AJAX.setRequestHeader('Content-type','application/x-www-form-urlencoded');
Uname_AJAX.onreadystatechange=_CheckUsernameDB;
Uname_AJAX.send("req=checkUname&Uname="+str);
}

function _CheckUsernameDB()
{
if(Uname_AJAX.readyState != 4)
 {

 }
 if(Uname_AJAX.readyState == 4)
 {
 re=Uname_AJAX.responseText
 if(re=="true")
  {
  document.getElementById("errMsg_txtUserName").innerHTML="Username already exists!";
  newUser_form_state=false;
  valid_uname=false;
  }else{
  //newUser_form_state=true;
  valid_uname=true;
  }
 }
}

function CheckValidData(str)
{
var illChar=/[\(\)\<\>\,\;\:\\\"\[\]\!\@\#\$\%\^\&\*\-\=\+\{\}\?\/\~\`]/;
if(str=="")
 {
 return true;
 }else{
 if(str.indexOf(" ")>=0) {return false;}
 if(str.match(illChar)) {return false;}
 }
}

function CheckValidStr(str)
{
var illChar=/[\(\)\<\>\,\;\:\\\"\[\]\!\@\#\$\%\^\&\*\-\=\+\{\}\?\/\~\`]/;
if(str=="")
 {
 return true;
 }else{
 //if(str.indexOf(" ")>=0) {return false;}
 if(str.match(illChar)) {return false;}
 }

}

function checkValidateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }else{
    return true;
   }
}

function checkValidNumber(str)
{
var reg
reg=str
if(str==""){return;}
 for(x=0;x<=reg.length-1;x++)
  {
  //48-57
  xc=reg.charCodeAt(x)
  //alert(xc)
  if((xc >=48 && xc <=57) || xc==32 || xc==45 || xc==43 || xc==46)
   {
   return true;
   }
  
  }
  return false;
}

function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  //newElm.value = "";
  if(oldElm.id) newElm.id = oldElm.id;
  if(iType=="password") newElm.className="left_textbox";
  if(iType=="text") newElm.className="left_textbox_blank";
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
  if(oldElm.title) newElm.title = oldElm.title;

  
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  
  
  newElm.onfocus = function(){return function(){
    if(this.hasFocus) return;
    var newElm = changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
    
  }}();

  
  newElm.onblur = function(){return function(){
   if(this.hasFocus) 
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
    
      changeInputType(this,'text',iValue,false,true);
      
    }
  }}();

  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!blankValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}


function NewUserSubmit()
{
if(document.frmMain.SecQuestion.value==""){document.getElementById("errMsg_SecQuestion").innerHTML="Please select question";newUser_form_state=false;}
if(document.frmMain.SecAnswer.value=="Secret Answer"){document.getElementById("errMsg_SecAnswer").innerHTML="Invalid Answer";newUser_form_state=false;}
if(!document.frmMain.SecQuestion.value==""){document.getElementById("errMsg_SecQuestion").innerHTML="";newUser_form_state=true;}
if(document.frmMain.txtUserName.value=="Username"){document.getElementById("errMsg_txtUserName").innerHTML="Invalid Username";newUser_form_state=false;}
if(document.frmMain.EmailID.value=="Email ID"){document.getElementById("errMsg_EmailID").innerHTML="Invalid Email ID";newUser_form_state=false;}
if(document.frmMain.FirstName.value=="First Name"){document.getElementById("errMsg_FirstName").innerHTML="Invalid First Name";newUser_form_state=false;}
if(document.frmMain.LastName.value=="Last Name"){document.getElementById("errMsg_LastName").innerHTML="Invalid Last Name";newUser_form_state=false;}
if(checkValidateEmail(document.frmMain.EmailID.value)==false){document.getElementById("errMsg_EmailID").innerHTML="Invalid Email ID";newUser_form_state=false;}
if(newUser_form_state==true && valid_uname==true)
 {
   document.getElementById("errMsg_SecAnswer").innerHTML="";
   document.getElementById("errMsg_txtRePassword").innerHTML="";
   document.getElementById("errMsg_EmailID").innerHTML="";
   document.getElementById("errMsg_FirstName").innerHTML="";
   document.getElementById("errMsg_LastName").innerHTML="";
   document.getElementById("errMsg_SecQuestion").innerHTML="";
   document.getElementById("errMsg_SecAnswer").innerHTML="";
   document.frmMain.method="post"
   document.frmMain.action="usercheck.asp?req=newusersave"
   document.frmMain.target="shem_silent_frame"
   document.frmMain.submit();
 }else{
 alert("You have filled incorrect form");
 }
}

function _newUserSaveResponse(str)
{
str2=str.split("|");
if(str2[0]=="OK")
 {
 alert("Registration Done. You can now log into your account.") 
 SignOut();
 }else{
 document.getElementById(str2[0]).innerHTML=str2[1];
 }
}

function CreateOutBox(title,msg,closebtn)
{
if(closebtn==""){closebtn="yes";}
if(document.getElementById("ob_back"))
 {
 rembox=document.getElementById("ob_back")
 pboxx=document.getElementById("pb_back")
 f=document.getElementById("selectblocker")
 document.body.removeChild(pboxx)
 document.body.removeChild(rembox)
 document.body.removeChild(f)
 }

sHeight=window.document.body.scrollHeight
sWidth=window.document.body.scrollWidth 

fr=document.createElement("iframe")
fr.id="selectblocker";
fr.style.position="absolute";
fr.style.top="0px";
fr.style.left="0px";
fr.style.width="0px";
fr.style.height="0px";
fr.frameBorder="0";
fr.scrolling="no";
fr.src="blank.htm"

document.body.appendChild(fr);

bBox=document.createElement("div")
bBox.className="popup_back_box"
bBox.id="ob_back"
bBox.style.position="absolute";
bBox.style.visibility="visible"
bBox.style.top="0px"
document.body.appendChild(bBox)

cBox=document.createElement("div")
cBox.className="popup_main_box"
cBox.id="pb_back"

stop=document.body.scrollTop;
stop=200+stop
cBox.style.top=stop+"px"

if(document.all)
{
cBox.style.position="absolute";
}else{
cBox.style.top="200px"
cBox.style.position="fixed";
}

cBox.style.visibility="hidden";



var tb;
tb="<table id='xtbl' border='0' width='250px' cellspacing='0' cellpadding='0' id='table2' bgcolor='#455C74' style='border: 1px solid #94A5B4; padding-left: 0px; padding-right: 0px; padding-top: 0px; padding-bottom: 0px;position:relative'>"
		tb=tb+"<tr>"
			tb=tb+"<td nowrap  colspan='2' bgcolor='#869BAE' id='ebox_title' style='padding:5px; color:#FFFFFF; font-family:Verdana; font-size:10pt; font-weight:bold'></td>"
			tb=tb+"<td width='27' bgcolor='#869BAE' align='right' ></td>"
		tb=tb+"</tr>"
		tb=tb+"<tr>"
			tb=tb+"<td colspan='3' style='padding:5px; font-family:Arial; font-size:10pt; color:#FFFFFF' id='ebox_msg'></td>"
		tb=tb+"</tr>"
		if(closebtn=="yes")
		{
		tb=tb+"<tr>";
			tb=tb+"<td colspan='3' style='padding:5px' id='ebox_msg' align='center'><input onclick='hide_popup()' class='form_box_button' type='button' value='Close'></td>";
		tb=tb+"</tr>";
		}
	tb=tb+"</table>"

//var nCon=document.createTextNode(tb)
cBox.innerHTML=tb
document.body.appendChild(cBox)

o_box=document.getElementById("ob_back")
p_box=document.getElementById("pb_back")
o_box.style.height=sHeight
o_box.style.width=sWidth
o_box.style.visibility="visible"
p_box.style.visibility="visible"
document.getElementById("ebox_title").innerHTML=title
document.getElementById("ebox_msg").innerHTML=msg
in_box_width=document.getElementById("xtbl").offsetWidth
in_box_height=document.getElementById("xtbl").offsetHeight
xleft=in_box_width/2
xleft=(sWidth/2)-xleft
p_box.style.left=xleft

if(document.all){
iFrameTag = document.getElementById("selectblocker");
iFrameTag.style.top=stop+"px";
iFrameTag.style.left=document.getElementById("pb_back").offsetLeft;
iFrameTag.style.width = document.getElementById("pb_back").offsetWidth;
iFrameTag.style.height = document.getElementById("pb_back").offsetHeight;
iFrameTag.style.zIndex =199;
}
}
function hide_popup()
{
o_box=document.getElementById("ob_back")
if(o_box){
}else{
return;
}
p_box=document.getElementById("pb_back")
o_box.style.visibility="hidden"
p_box.style.visibility="hidden"
document.getElementById("ebox_title").innerHTML=""
document.getElementById("ebox_msg").innerHTML=""
iFrameTag = document.getElementById("selectblocker")
if(iFrameTag)
 {
 iFrameTag.style.width="0px"
 iFrameTag.style.height="0px"
 } 
}


function Product_Search()
{
str=document.frmMain.txtStr.value
if(str=="" || str=="Enter Keyword"){return;}
xfld=document.frmMain.strFld.value
window.location="ProductList.asp?pgtype=search&in="+xfld+"&str="+str
}
function Genre_Search()
{
str=document.frmMain.strGenre.value
if(str!="")
 {
 window.location="ProductList.asp?pgtype=search&in=genre&str="+str
 }
}
function MRP_Search()
{
str=document.frmMain.strMRP.value
if(str!="")
 {
 window.location="ProductList.asp?pgtype=search&in=MRP&str="+str
 }
}