// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();        
}}

function fetch_lageimg(id)
	{

		var imgget = document.getElementById(id).src;

		var mySplitResult = imgget.split("/");
	 	for(i = mySplitResult.length-1; i>mySplitResult.length-3; i--)
		{
			var folderName = mySplitResult[mySplitResult.length-3];
			var subFolderName = mySplitResult[mySplitResult.length-2];
			var fileName =  mySplitResult[mySplitResult.length-1];
			var t = '<img src="product-images/'+folderName+'/'+subFolderName+'/'+fileName+'">';
			document.getElementById('mainImg').innerHTML = t;
			break;
		}
		return true;
	}

	function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

function addEmailTo(friendName, checkStatus) {
	alert(friendName);
	var parentForm = window.parent.document.ShareForm ? window.parent.document.ShareForm : window.parent.document.create_submit;
	var pattern = new RegExp.escape(friendName);
	var recipientsString = parentForm.recipients.value;
	if (recipientsString.indexOf(friendName) != -1) return;
	//checkbox is checked; add recipient to string
	if (checkStatus==1) {
		//string has no recipients; add first recipient to string
		if (recipientsString=="") {
			parentForm.recipients.value = friendName;
			recipientsString = parentForm.recipients.value;
		}
		//string has recipients; append recipient to string
		else {
			parentForm.recipients.value = recipientsString + ", " + friendName;
			recipientsString = parentForm.recipients.value;
		}
	}
	//checkbox is unchecked; remove recipient from string
	else {
		//recipient in the string; remove recipient
		if (recipientsString.search(pattern)!=-1){
			parentForm.recipients.value = recipientsString.replace(friendName, '');
			recipientsString = parentForm.recipients.value;
		}
	}
	removeCommas();
}

function updateParent()
{
	var addresses = new Array("bal.krishan@parsoftwares.com");
	if (window.parent.update_addresses) window.parent.update_addresses(addresses);
}

function updateCheckboxes() {
  //set all checkboxes to unchecked
	for (i=1;i<document.addressForm.length;i++){
	  document.addressForm.elements[i].checked=false;
  }
	var parentForm = window.parent.document.ShareForm ? window.parent.document.ShareForm : window.parent.document.create_submit;
     var recipientsString= parentForm.recipients.value;
		 recipientsArray = recipientsString.split(',');
		 //see if recipient String matches checkbox; if match then check it
		 for (i=0;i<recipientsArray.length;i++) {
		   var tempRecipient=trimString(recipientsArray[i]);

			 for (j=1;j<document.addressForm.length;j++){
         if (tempRecipient==document.addressForm.elements[j].value) {
				 document.addressForm.elements[j].checked=true;
				 }	         
      }
	}
	removeCommas();

}

function initContacts()
{
	updateParent();
//	updateCheckboxes();
}



function removeCommas() {
	var parentForm = window.parent.document.ShareForm ? window.parent.document.ShareForm : window.parent.document.create_submit;
        recipientsString = parentForm.recipients.value;
			  //remove extra commas			 
			  if (recipientsString.search(/\s*,\s*,\s*/)!=-1) {
			    parentForm.recipients.value = recipientsString.replace(/\s*,\s*,\s*/, ', ');
				  recipientsString = parentForm.recipients.value;
		    }
					
			 //Split string into array of recipientss			
		   recipientsArray = recipientsString.split(', ');
		   //extra comma in beginning of recipientString; remove first comma
		   if (recipientsArray[0]=='') {
			   parentForm.recipients.value = recipientsString.substring(2);
			   recipientsString = parentForm.recipients.value;
	     }
		   //extra comma in end of recipientString; remove last comma	 
	     if (recipientsArray[recipientsArray.length-1]=='') {
			   parentForm.recipients.value = recipientsString.substring(0,recipientsString.length-2);
			   recipientsString = parentForm.recipients.value;
	     }
}

function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}


RegExp.escape = function(text) {
  if (!arguments.callee.sRE) {
    var specials = [
      '/' ,'@', '.', '*', '+', '?', '|',
      '(', ')', '[', ']', '{', '}', '\\'
    ];
    arguments.callee.sRE = new RegExp(
      '(\\' + specials.join('|\\') + ')', 'g'
    );
  }
  return text.replace(arguments.callee.sRE, '\$1');
}

function CheckAll() {
  var recipientsString = window.parent.document.ShareForm.recipients.value;
   if (recipientsString!='') {
	   recipientsString = recipientsString + ', ';
	 }
	//set checkbox to checked; if Recipients string does not contain friend, then add friend
	for (i=0;i<document.addressForm.contact.length;i++){
	  document.addressForm.contact[i].checked=true;
		pattern = document.addressForm.contact[i].value;
    if (recipientsString.search(pattern)==-1) {
		   recipientsString = recipientsString + pattern + ', ';
		}
  }
	window.parent.document.ShareForm.recipients.value = recipientsString;
}

function ClearAll() {
  var recipientsString = window.parent.document.ShareForm.recipients.value;
	//set checkbox to checked; if Recipients string contains friend, then remove friend
	for (i=0;i<document.addressForm.contact.length;i++){
	  document.addressForm.contact[i].checked=false;
		pattern = document.addressForm.contact[i].value;
	    //recipient in the string; remove recipient
	    if (recipientsString.search(pattern)!=-1){
			  window.parent.document.ShareForm.recipients.value = recipientsString.replace(pattern, '');
				removeCommas();
			  recipientsString = window.parent.document.ShareForm.recipients.value;
	    }

  }
	window.parent.document.ShareForm.recipients.value = recipientsString;
}

  function get(obj) {
      var poststr = "recipients=" + encodeURI( document.getElementById("recipients").value )+
	  "," + encodeURI( document.getElementById("videoid").value );

	  //alert(poststr);
      makePOSTRequest('/uploads/sendLink', poststr);
   }
