/****************************************************************************************
*               Copyright © 2004 by Blue Star Infotech Inc.								*
*				All rights reserved														*
*               Project - alaskachannel for Alaska 										*
*****************************************************************************************
*   File name:				common.js													*
*   Description:			This file contains common javascript functions that are		*
*							used in various jsp files. This file contains functions for *
*							validating email, firstname, lastname, password, refreshing *
*							opener window etc. 
*   Author:					Abhinav Kumar   											*
*   Date Created:			November 10 2004											*
*   Version:																			*
*****************************************************************************************
*   Change History:																		*
*																						*
*   No 		Date			By                     Description							*
*																						*
****************************************************************************************/

function popupEmail($url) {

  // SET MESSAGE VALUES
  var to = "";
  var cc = "";
  var bcc = "";
  var subject = "Alaska Travel Advice From Alaska.org";
  var body = 
      "I thought you would be interested in this page I found on Alaska.org:\n\n "+$url

  // BUILD MAIL MESSAGE COMPONENTS 
  var doc = "mailto:" + to + 
      "?cc=" + cc + 
      "&subject=" + escape(subject) + 
      "&body=" + escape(body); 

  // POP UP EMAIL MESSAGE WINDOW
  window.location = doc;
}

function showHide(block){
	var the_block = eval('document.getElementById("' + block +'")');
	if (the_block.style.display=="block" || the_block.style.display=="" ){
		the_block.style.display="none";
	}else{
		the_block.style.display="";
	}
}

function bookmarkPage(){
	if (window.external) { 
		window.external.AddFavorite(location.href, document.title);
		$msg = "Thank you for bookmarking this page.";
	} else {
		$msg = "You can bookmark this page by clicking CTRL-D.";
	}
	alert($msg);
}

var moreVideoAndPhoto = ""; // to disable the more video and photo link if no images are available
var breadcrumbInPhotoAndVideoFrame = ""; // to make breadcrumb availabe on video and photo page

function LoginCheckForSendToFriend(userLoggedIn){
	//var userLoggedIn = "<%= session.getValue("userLoggedIn")%>";
	if (userLoggedIn=="true"){	
		window.open('/admin/popup_sendtoFriend.jsp','popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
	}
	else
	{
		//"<% session.putValue("userLoggedIn","true");%>"
// THIS IS THE OLD, CORRECT VERSION		window.open('/admin/LoginDetails.jsp','popup','height=510,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
		window.open('/admin/popup_sendtoFriend.jsp','popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
		//window.location.href = window.location.href;
	}
}

function LoginCheckForSendToFriendAtAdmin(userLoggedIn){
	//var userLoggedIn = "<%= session.getValue("userLoggedIn")%>";
	if (userLoggedIn=="true"){	
		window.open('/admin/popup_sendtoFriend.jsp','popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
	}
	else
	{
		//"<% session.putValue("userLoggedIn","true");%>"
// THIS IS THE OLD CORRECT VERSION		window.open('/admin/LoginDetails.jsp','popup','height=510,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
		window.open('/admin/popup_sendtoFriend.jsp','popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
		//window.location.href = window.location.href;
	}
}

function LoginCheckForCustomerReview(userLoggedIn){
//	//var userLoggedIn = "<%= session.getValue("userLoggedIn")%>";
//	if (userLoggedIn=="true"){	
		window.open('/admin/popup_CustRev_submit.jsp','popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
//	}
//	else
//	{
//		//"<% session.putValue("userLoggedIn","true");%>"
//		window.open('../../admin/LoginDetails.jsp','popup','height=510,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
//		//window.location.href = window.location.href;
//	}
}

function LoginCheckForCustomerReviewForInnerFolders(userLoggedIn,supplierId){
//	//var userLoggedIn = "<%= session.getValue("userLoggedIn")%>";
//	if (userLoggedIn=="true"){	
		window.open("/admin/popup_CustRev_submit.jsp?supplier="+supplierId+"",'popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
//	}
//	else
//	{
//		//"<% session.putValue("userLoggedIn","true");%>"
//		window.open('../../admin/LoginDetails.jsp','popup','height=510,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
//		//window.location.href = window.location.href;
//	}
}


function LoginCheckForPostYourReviewForInnerFolders(userLoggedIn){ // made by abhinavk
//	//var userLoggedIn = "<%= session.getValue("userLoggedIn")%>";
	var supplierID = document.getElementById("breadcrump").innerHTML;
//	if (userLoggedIn=="true"){	
		window.open("/admin/popup_CustRev_submit.jsp?supplier="+supplierID+"",'popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
//	}
//	else
//	{
//		//"<% session.putValue("userLoggedIn","true");%>"
//		window.open('../../admin/LoginDetails.jsp','popup','height=510,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false')
//		//window.location.href = window.location.href;
//	}
}


function fogotPasswordPage(){
	location.href="popup_forgot_password.jsp";
}
function NewUserRegistrationPage(){
	location.href="NewUserRegistration.jsp";
}

function refreshOpenerWindow(){	

	if (!(typeof(window.opener) == "undefined")){
		window.opener.location.reload(true);
	}
window.close();
}

function closeWindow(){	
	if (!(typeof(window.opener) == "undefined")){
		window.opener.location.reload(true);
		window.close();
	}
}

function setCursor(textControl){ 
	textControl.focus();
}

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 ValidateEmail(emailID){

	if ((emailID.value==null)||(emailID.value=="")||(emailID.value==" ")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (emailCheck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

// function added for validating myltiple email id seperated by comma

function ValidateEmailForMultipleRecipients(emailID){

	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeckForMultipleRecipients(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

function trimAll(sString) {
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
		}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
return sString;
}

function echeckForMultipleRecipients(commaSeperatedString){

		var splitString = commaSeperatedString.split(",");
		for (var i =0 ;i< splitString.length ; i++){
			if(emailCheck(trimAll(splitString[i]))== false){
				return false
			}
		}
		return true
}

// this emailCheck function is used for very strict email ress checking
function emailCheck (emailStr) {

	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	//var checkTLD=1;
	var checkTLD=0;// we don't need to check for TLD

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

		var matchArray=emailStr.match(emailPat);

		if (matchArray==null) {

		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */

		alert("Email address seems incorrect (check @ and .'s)");
		return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];

		// Start by checking that only basic ASCII characters are in the strings (0-127).

		for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
		alert("Ths username contains invalid characters.");
		return false;
		   }
		}
		for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
		alert("Ths domain name contains invalid characters.");
		return false;
		   }
		}

		// See if "user" is valid 

		if (user.match(userPat)==null) {

		// user is not valid

		alert("The username doesn't seem to be valid.");
		return false;
		}

		/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */

		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {

		// this is an IP address

		for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
		alert("Destination IP address is invalid!");
		return false;
		   }
		}
		return true;
		}

		// Domain is symbolic name.  Check if it's valid.
		 
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
		alert("The domain name does not seem to be valid.");
		return false;
		   }
		}

		/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding 
		the domain or country. */

		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
		}

		// Make sure there's a host name preceding the domain.

		if (len<2) {
		alert("This address is missing a hostname!");
		return false;
		}

		// If we've gotten this far, everything's valid!
		return true;
}


function ValidatePassword(password){
	if ((password.value==null)||(password.value=="")){
		alert("Please Enter your password")
		password.focus()
		return false
	}
	if (validatePwd(password.value)==false){
		password.value=""
		password.focus()
		return false
	}
	return true
}

function validatePwd(str) {
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	//var pw1 = document.myForm.password.value;
	//var pw2 = document.myForm.password2.value;

		// check for a value in both fields.
		/*if (pw1 == '' || pw2 == '') {
		alert('Please enter your password twice.');
		return false;
		}*/

		// check for minimum length
		/*if (document.myForm.password.value.length < minLength) {
		alert('Your password must be at least ' + minLength + ' characters long. Try again.');
		return false;
		}*/

		// check for spaces
		/*if (document.myForm.password.value.indexOf(invalid) > -1) {
			alert("Sorry, spaces are not allowed.");
			return false;
			}
		else {
			if (pw1 != pw2) {
				alert ("You did not enter the same new password twice. Please re-enter your password.");
				return false;
				}
			else {
				alert('Nice job.');
				return true;
				}
			}*/
		if (str.indexOf(invalid) > -1) {
			alert("Sorry, spaces are not allowed.");
			return false;
			}
		return true;
	}


function ValidateFirstname(firstname){
	if ((firstname.value==null)||(firstname.value=="")){
		alert("Please Enter your firstname")
		firstname.focus()
		return false
	}
	return true
}


function checkSpecialCharForName(str){
	var i=0;
	for(i; i<str.length; i++)
		{
			var c = str.charAt(i);
			if ( ! ((c >="A") && (c <="Z") || (c >="a") && (c <="z")) ){	
				return false;
				}
		}
	return true;	
}

function ValidateLastname(lastname){
	if ((lastname.value==null)||(lastname.value=="")){
		alert("Please Enter your lastname")
		lastname.focus()
		return false
	}
	return true
}

function ValidateFullname(fullname){
	if ((fullname.value==null)||(fullname.value=="")||(fullname.value==" ")){
		alert("Please Enter your name")
		fullname.focus()
		return false
	}
	if (checkSpecialCharForFullName(fullname.value)==false){
		alert("Invalid name")
		fullname.value=""
		fullname.focus()
		return false
	}
	return true
}

function checkSpecialCharForFullName(str){
	var i=0;
	for(i; i<str.length; i++)
		{
			var c = str.charAt(i);
			if ( ! ((c >="A") && (c <="Z") || (c >="a") && (c <="z") || (c==" ")) ){	
				return false;
				}
		}
	return true;	
}

function checkMessageLength(str){
	if(str.value.length>25000){
	alert("Message size should be less than 25000 Char");
	return false;
	}
	return true;
}
		

function mailSupplierTest(suppliername){
	window.open("../admin/popup_mailtoSupplier.jsp?supplier="+suppliername+"",'popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false');
}

function mailSupplierID(suppliername){
	str1 = suppliername.split(" ");
	supplierID = "";
	for(i=0; i< str1.length; i++){
	if(!str1.length-1){
			supplierID  += str1[i] + "_";
		}
	}
	suppliername1  = supplierID.slice(0,supplierID.length-1);	
	window.open("../admin/popup_mailtoSupplier.jsp?supplier="+suppliername1+"",'popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false');
}

function mailSupplier1(suppliername){
	window.open("../admin/popup_mailtoSupplier.php?supplier="+suppliername+"",'popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false');
}

function mailSupplier(){
	var supplierID = document.getElementById("breadcrump").innerHTML;
	str1 = supplierID.split(" ");
	supplier_ID = "";
	for(i=0; i< str1.length; i++){
	if(!str1.length-1){
		supplier_ID  += str1[i] + "_";
		}
	}
	suppliername  = supplier_ID.slice(0,supplier_ID.length-1);
	window.open("../admin/popup_mailtoSupplier.jsp?supplier="+suppliername+"",'popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false');
}

function maxlength(element, label, maxvalue)
     {
     //var q = eval("document.pooh."+element+".value.length");
	 var q = eval("element.value.length");
     //var r = q - maxvalue;
     /*var msg = "Sorry, you have input "+q+" characters into the "+
       "text area box you just completed. It can return no more than "+
       maxvalue+" characters to be processed. Please abbreviate "+
       "your text by at least "+r+" characters";*/
	 
	 var msg = ""+label+" can not be more than "+maxvalue+" characters!";
     if (q >= maxvalue) { 
		 alert(msg);
 		//element.value=""
		//element.focus()
		return false;
	 }
	 return true;
    }

function minlength(element, label, minvalue)
     {
     //var q = eval("document.pooh."+element+".value.length");
 	 var q = eval("element.value.length");
     //var r = q - maxvalue;
     /*var msg = "Sorry, you have input "+q+" characters into the "+
       "text area box you just completed. It can return no more than "+
       maxvalue+" characters to be processed. Please abbreviate "+
       "your text by at least "+r+" characters";*/
	 
	 var msg = ""+label+" can not be less than "+minvalue+" characters!";
	 if (q < minvalue) {
		 alert(msg);
  		element.value=""
		element.focus()
		return false;
	 }
	 return true;
   }


function maxlengthTextArea(element, label, maxvalue)
     {
     //var q = eval("document.pooh."+element+".value.length");
	 var q = eval("element.value.length");
     var r = q - maxvalue;
     var msg = "Sorry, you have input "+q+" characters into the "+
       "text area box you just completed. It can return no more than "+
       maxvalue+" characters to be processed. Please abbreviate "+
       "your text by at least "+r+" characters";
	 
     if (q >= maxvalue) { 
		 alert(msg);
 		//element.value=""
		//element.focus()
		return false;
	 }
	 return true;
    }

function countNoOfCitiesSelected(multipleDropDown, limit, limitinwords){
	var lengthOfDropDown = multipleDropDown.options.length;
	var countOfSelectedItems = 0;

	for (var i=0; i< lengthOfDropDown; i++){
		if(multipleDropDown.options[i].selected){
			++countOfSelectedItems;
			if (countOfSelectedItems > limit){
						alert("Sorry you can't select more than "+limitinwords+" items!");
						multipleDropDown.options[i].selected = false;
						return false;
					}
			}
	}
	return true;
}

function validateForm(multipleDropDown){
	var lengthOfDropDown = multipleDropDown.options.length;

	for (var i=0; i< lengthOfDropDown; i++){
		if(multipleDropDown.options[i].selected){
			return true;
		}
	}
	alert("Please select at least one of the Alaska Places!");
	multipleDropDown.focus();
	return false;
}


function checkForRows(totalRows,checkboxes){
	var anyCheckBoxSelected = false;
	if ( totalRows <= 0 ){
		alert("Sorry, no entry available!");
		return false;
	}

	if (totalRows == 1){
         if (checkboxes.checked == true) {
		 anyCheckBoxSelected = true;
		}
	}
	else{
		for (i=0; i< totalRows ; i++) {
			if (checkboxes[i].checked == true) {
			anyCheckBoxSelected = true;
		 }
      }
	}

	if (anyCheckBoxSelected == false){
		alert("Sorry, No selection made!");
	}

return (true&&anyCheckBoxSelected);
}

function ValidateReview(title,loc,reviewerloc,review, fullname, emailID){
	if ((title.value==null)||(title.value=="")){
		alert("Please Enter your Title");
		title.focus();

		return false;
	}
/*	if ((loc.value==null)||(loc.value=="")){
		alert("Please Enter your Review Location")
		loc.focus();
		return false;
	}
*/

	if ((fullname.value==null)||(fullname.value=="")){
		alert("Please Enter your name")
		fullname.focus()
		return false
	}
	if (checkSpecialCharForFullName(fullname.value)==false){
		alert("Invalid name")
		fullname.value=""
		fullname.focus()
		return false
	}


	if (checkSpecialCharForName(loc.value)==false){
		alert("Invalid Location")
		loc.value=""
		loc.focus()
		return false
	}

	if ((reviewerloc.value==null)||(reviewerloc.value=="")){
		alert("Please Enter your Location");
		reviewerloc.focus();
		return false;
	}

	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (emailCheck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}

	
	
	if ((review.value==null)||(review.value=="")){
		alert("Please Enter your Review");
		review.focus();
		return false;
	}
	
	return true
}


function retrivereviews(SupplierId)  {
	window.open("/fishing/retrieveReviews.do?supplier="+SupplierId+"",'popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false') ;
}

function customerReviews(){ // customer review added by shanmugam and abhinav
var supplierID = document.getElementById("breadcrump").innerHTML;
window.open("/fishing/retrieveReviews.do?supplier="+supplierID+"",'popup','height=600,width=600,top=10,left=10,toolbar=false,location=false,status=yes,menubar=false,scrollbars=yes,resizable=false') ;

}


function ValidateAddressForContactUsForm(address1 , address2){
	if (((address1.value==null)||(address1.value=="")) && ((address2.value==null)||(address2.value==""))){
		
		alert("Please Enter your address")
		address1.focus()
		return false
	}

/*	if (checkSpecialCharForFullName(address1.value)==false){
		alert("Invalid address")
		address1.value=""
		address1.focus()
		return false
	}

	if (checkSpecialCharForFullName(address2.value)==false){
		alert("Invalid address")
		address2.value=""
		address2.focus()
		return false
	}
*/
	return true
}

function ValidateCity(city){
	if ((city.value==null)||(city.value=="")){
		alert("Please Enter your city")
		city.focus()
		return false
	}
	return true
}

function ValidateZip(zip){
	if ((zip.value==null)||(zip.value=="")){
		alert("Please Enter your Zip/Postal Code")
		zip.focus()
		return false
	}
	return true
}

function ValidateDaytimePhone(daytimephone){
	return true
}


function checkForZipOrPhone(str){
	var valid = "0123456789-";
	for(var i=0; i<str.length; i++)
		{
			var c = str.charAt(i);
			if (valid.indexOf(c) == "-1") {
				return false;
				}
		}
	return true;	
}


	function validateConctactUsFormInCommon(contactusfromobject){
		return (ValidateFullname(contactusfromobject.Name) &&
				ValidateAddressForContactUsForm(contactusfromobject.Address1, contactusfromobject.Address2)  &&
				ValidateCity(contactusfromobject.City) &&
				ValidateZip(contactusfromobject.PrimaryInformation_Zip) &&
				ValidateEmail(contactusfromobject.Email));
	}



//author: Thiru
function createPhotogallery(){
//alert("inside createPhotogallery");
tempId = document.getElementById("main-breadcrump").innerHTML;
temp_Id = document.getElementById("breadcrump").innerHTML;
//alert(temp_Id);
tempId1 = tempId.split("<");
//alert(tempId1.length);
tempId3=" ";
for(i=0; i< tempId1.length; i++){
	tempId2 = tempId1[i].split(">");
	for(j=0; j< tempId2.length; j++){
		if(i==0){
			firsttname = tempId2[0].split(" &nbsp;");
			firstname = firsttname[0];	
		}
		
		if(!j==0){
		
			//alert(i + " : " + j + " = " + tempId2[j]);
			tempId3 += tempId2[j]
			
		}

	}
}
//alert(firstname);
fullname = tempId3.split(" &nbsp;»&nbsp; ");
//fullname.unshift(firstname);
//alert(temp_Id);
//fullname.push(temp_Id);
//fullname = fullname.split(" , ");


fullnameString = "";
	for(i=0; i< fullname.length; i++){
	//if(!fullname.length-1){
			fullnameString  +=  "."+fullname[i];
		//}
	}
	//alert(fullnameString.length);
	suppliername  = firstname + fullnameString.slice(0,fullnameString.length-0)+temp_Id;
	
	suppliername = suppliername.split(". ");
	
breadcrumpValue = " ";
breadcrumbValueForBreadcrumb = " ";
for(i=0; i<suppliername.length; i++){

breadcrumpValue += suppliername[i]+".";

}

breadcrumpValue = breadcrumpValue.slice(0,breadcrumpValue.length-1);

//breadcrumpValue = breadcrumpValue.replace("&amp;","and");
//breadcrumpValue = breadcrumpValue.replace("&amp;","replacementForAmpersnad");

//RepalcementForAmpersand
var	toReplace = "&amp;"; // replace this
var toAdd = "replacementForAmpersnad"; // with this
	
breadcrumpValue = replaceAll(breadcrumpValue,toReplace,toAdd);


//RepalcementForSingleQuotes
var	out = "'"; // replace this
var add = "RepalcementForSingleQuotes"; // with this
	
breadcrumpValue = replaceAll(breadcrumpValue,out,add);


// abhinavk :  i am adding this before every category "BLUE STAR SCHEMA."
breadcrumpValue = trimAll(breadcrumpValue);
breadcrumbValueForBreadcrumb = breadcrumpValue;

if (breadcrumpValue.indexOf("Overview") != -1){
	if (breadcrumpValue.indexOf("Overview") + 8 == breadcrumpValue.length){
		//alert(breadcrumpValue.indexOf("Overview"))
		//alert("overview is present in breadcrumb")
		//alert(breadcrumpValue.length)
		//alert(breadcrumpValue.substring(0,(breadcrumpValue.indexOf("Overview")-1)))
		breadcrumpValue = breadcrumpValue.substring(0,(breadcrumpValue.indexOf("Overview")-1));
	}
}


breadcrumpValue = "BLUE STAR SCHEMA." + breadcrumpValue;



// to make breadcrumpValue availabe for more video and photo link
breadcrumbInPhotoAndVideoFrame = breadcrumpValue; 


//alert("breadcrumb value " + breadcrumpValue);


//alert(" breadcrumbInPhotoAndVideoFrame in create photo gallery" +breadcrumbInPhotoAndVideoFrame);
	document.write('<iframe src="/common/photogallery/thumbnailPhotoGalleryManagement.jsp?suppliername='+ breadcrumpValue +'&forBreadcrumb='+ breadcrumbValueForBreadcrumb +' " frameborder="0" scrolling="auto" width="250" height="215" ></iframe>');
}



//author: Thiru
function createPhotogalleryOnSupplierPages(){
//alert("inside createPhotogallery");
tempId = document.getElementById("main-breadcrump").innerHTML;
temp_Id = document.getElementById("breadcrump").innerHTML;
//alert(temp_Id);
tempId1 = tempId.split("<");
//alert(tempId1.length);
tempId3=" ";
for(i=0; i< tempId1.length; i++){
	tempId2 = tempId1[i].split(">");
	for(j=0; j< tempId2.length; j++){
		if(i==0){
			firsttname = tempId2[0].split(" &nbsp;");
			firstname = firsttname[0];	
		}
		
		if(!j==0){
		
			//alert(i + " : " + j + " = " + tempId2[j]);
			tempId3 += tempId2[j]
			
		}

	}
}
//alert(firstname);
fullname = tempId3.split(" &nbsp;»&nbsp; ");
//fullname.unshift(firstname);
//alert(temp_Id);
//fullname.push(temp_Id);
//fullname = fullname.split(" , ");


fullnameString = "";
	for(i=0; i< fullname.length; i++){
	//if(!fullname.length-1){
			fullnameString  +=  "."+fullname[i];
		//}
	}
	//alert(fullnameString.length);
	suppliername  = firstname + fullnameString.slice(0,fullnameString.length-0)+temp_Id;
	
	suppliername = suppliername.split(". ");
	
breadcrumpValue = " ";
breadcrumbValueForBreadcrumb = " ";
for(i=0; i<suppliername.length; i++){

breadcrumpValue += suppliername[i]+".";

}

breadcrumpValue = breadcrumpValue.slice(0,breadcrumpValue.length-1);

//RepalcementForAmpersand
var	toReplace = "&amp;"; // replace this
var toAdd = "replacementForAmpersnad"; // with this
	
breadcrumpValue = replaceAll(breadcrumpValue,toReplace,toAdd);

//RepalcementForSingleQuotes
var	out = "'"; // replace this
var add = "RepalcementForSingleQuotes"; // with this
	
breadcrumpValue = replaceAll(breadcrumpValue,out,add);


// to make breadcrumpValue availabe for more video and photo link
breadcrumbInPhotoAndVideoFrame = breadcrumpValue; 

// abhinavk :  i am adding this before every category "BLUE STAR SCHEMA."
breadcrumpValue = trimAll(breadcrumpValue);

breadcrumbValueForBreadcrumb = breadcrumpValue;

if (breadcrumpValue.indexOf("Overview") != -1){
	if (breadcrumpValue.indexOf("Overview") + 8 == breadcrumpValue.length){
		//alert(breadcrumpValue.indexOf("Overview"))
		//alert("overview is present in breadcrumb")
		//alert(breadcrumpValue.length)
		//alert(breadcrumpValue.substring(0,(breadcrumpValue.indexOf("Overview")-1)))
		breadcrumpValue = breadcrumpValue.substring(0,(breadcrumpValue.indexOf("Overview")-1));
	}
}

breadcrumpValue = "BLUE STAR SCHEMA." + breadcrumpValue;



//alert("breadcrumb value " + breadcrumpValue);

//alert(" breadcrumbInPhotoAndVideoFrame in create photo gallery" +breadcrumbInPhotoAndVideoFrame);
	document.write('<iframe src="/common/photogallery/thumbnailPhotoGalleryManagementForSupplierPages.jsp?suppliername='+ breadcrumpValue +'&forBreadcrumb='+ breadcrumbValueForBreadcrumb +' " frameborder="0" scrolling="auto" width="500" height="215" ></iframe>');
}



function ChangeToBigPicture(BigPicture, IndexOfBigImage, Location, Credit, Title, Caption){
	//alert("in ChangeToBigPicture IndexOfBigImage: "+IndexOfBigImage);
	//alert("in ChangeToBigPicture IndexOfBigImage BigPicture: "  +BigPicture);
	
	/*
	var	out = "'"; // replace this
    var add = "\\\\'"; // with this

    var ret = "";
    var item=BigPicture.split("'");

	for(var i=0;i<item.length-1;i++)
       {
          ret+=item[i];
          ret+=add;
       }
      ret+=item[item.length-1];

	BigPicture = ret;*/

	var	out = "RepalcementForSingleQuotes"; // replace this
    var add = "'"; // with this

	var	out1 = "RepalcementForDoubleQuotes"; // replace this
	var add1 = '\"'; // with this

	BigPicture = replaceAll(BigPicture,out,add);
	//IndexOfBigImage = replaceAll(IndexOfBigImage,out,add);
	Location = replaceAll(Location,out,add);
	Credit = replaceAll(Credit,out,add);
	Title = replaceAll(Title,out,add);
	Caption = replaceAll(Caption,out,add);
	Caption = replaceAll(Caption,out1,add1);

	if (null != BigPicture && BigPicture != "null" && BigPicture != "/null"){
		//alert("i am ");
		var obj;
		obj = document.getElementById("BIG");
		obj.src=BigPicture;
		obj.name = IndexOfBigImage;

		var locationObj = document.getElementById("LOCATION");
		locationObj.innerHTML = "Location : " + Location;

		var creditObj = document.getElementById("CREDIT");
		creditObj.innerHTML = "Credit : " + Credit;

		var titleObj = document.getElementById("TITLE");
		titleObj.innerHTML = Title;

		var captionObj = document.getElementById("CAPTION");
		//alert(Caption);
		captionObj.innerHTML = Caption;

	}
}


function videophotoBlastOutImage(){
		//alert("i am ");
		var obj;
		obj = document.getElementById("BIG");
		//alert(obj);
		//alert(obj.src);
		var mediumimage = obj.src;
		var largeimage = mediumimage.replace("medium","big");
		//alert(largeimage)
		largeimage = replaceAll(largeimage,'&','replacementForAmpersnad');
		//alert(largeimage)
		//window.open(largeimage);
		window.open('/videos-photos/vp_anchorage_ss01_photo_enlarge.jsp?image='+largeimage,'popup','height=700,width=800,top=10,left=10,toolbar=false,location=false,status=false,menubar=false,scrollbars=yes,resizable=yes')
}

function MostRecentCustomerReview(){
var supplierID = document.getElementById("breadcrump").innerHTML;
document.write('<iframe id="mostRecentReviewIframe" src="/common/customerreview/mostrecentcustomerreview.jsp?suppliername='+ supplierID +'" frameborder="0" scrolling="no" WIDTH="100%" HEIGHT="60"></iframe>');

}


function replaceAll( strToBeOperated, strToBeReplaced, strForReplacement ) {
	//alert("iam in ");
    for ( i = 0; i < strToBeOperated.length; i++ ) {
        var idx = strToBeOperated.indexOf(strToBeReplaced);

        while ( idx > -1 ) {
            strToBeOperated = strToBeOperated.replace(strToBeReplaced,strForReplacement ); 
            idx = strToBeOperated.indexOf(strToBeReplaced);
        }

    }

    return strToBeOperated;
}


function NextMediumImageNotInUse(gsArrayForImages, totalNoOfimage){

//alert("1");
//alert(totalNoOfimage);
		var obj;
		var currentIndexOfImage = -1;
		var nextIndexOfImage = -1;
//alert("2");		
		obj = document.getElementById("BIG");
//alert("3");
		currentIndexOfImage = obj.name;
//alert("4");
//alert("5");
		nextIndexOfImage = parseInt(currentIndexOfImage) + 3;
		
		if (nextIndexOfImage > totalNoOfimage)
		{
			alert("You are on the last image");
			return false;
		}
		
// affected due to database change		
		obj.src="/"+gsArrayForImages[nextIndexOfImage];
//alert("6");
		obj.name = nextIndexOfImage;
//alert("7");
//alert("totalNoOfimage " + totalNoOfimage);
//alert("currentIndexOfImage "+currentIndexOfImage);
//alert("nextIndexOfImage " +nextIndexOfImage);
//alert(gsArrayForImages[nextIndexOfImage]);

		return true;
}



function PreviousMediumImageNotInUse(gsArrayForImages){

//alert("1");
		var obj;
		var currentIndexOfImage = -1;
		var nextIndexOfImage = -1;
//alert("2");		
		obj = document.getElementById("BIG");
//alert("3");
		currentIndexOfImage = obj.name;
//alert("4");
//alert("5");
		nextIndexOfImage = parseInt(currentIndexOfImage) - 3;
		
		if (nextIndexOfImage <0){
			alert("You are on the first image");
			return false;
		}
// affected due to database change		
		obj.src="/"+gsArrayForImages[nextIndexOfImage];
//alert("6");
		obj.name = nextIndexOfImage;
//alert("7");

//alert("currentIndexOfImage "+currentIndexOfImage);
//alert("nextIndexOfImage " +nextIndexOfImage);
//alert(gsArrayForImages[nextIndexOfImage]);
		return true;
}

function moreVideoAndPhotoLinkActivation(noOfVideosAndImagesInDatabase)
{
	moreVideoAndPhoto = noOfVideosAndImagesInDatabase;
	//alert("moreVideoAndPhotoLinkActivation");
	//alert("noOfImageInDatabase "+noOfImageInDatabase);
	//alert("moreVideoAndPhoto "+moreVideoAndPhoto);

}

function writeMoreVideoAndPhotoLink(breadcrumbInPhotoAndVideoFrame, breadcrumbInPhotoAndVideoFrameForBreadcrumb)
{

	newbreadcrumbInPhotoAndVideoFrame = breadcrumbInPhotoAndVideoFrame ;
	newbreadcrumbInPhotoAndVideoFrameForBreadcrumb = breadcrumbInPhotoAndVideoFrameForBreadcrumb;
	//alert("moreVideoAndPhoto in final "+moreVideoAndPhoto);
	//alert("breadcrumbInPhotoAndVideoFrame in final with thiru "+ breadcrumbInPhotoAndVideoFrame);
	//alert("newbreadcrumbInPhotoAndVideoFrame with thiru" + newbreadcrumbInPhotoAndVideoFrame)



	if (moreVideoAndPhoto != 0){
		document.write('<tr><td height="25" colspan="5" class="text-06">Click on the thumbnails to enlarge</td></tr>');
		document.write('<tr><td colspan="5">');
		document.write('<a href="javascript:SendCategoryInfoToFinalPage(newbreadcrumbInPhotoAndVideoFrame,newbreadcrumbInPhotoAndVideoFrameForBreadcrumb)" class="blu-link-02" >More Videos &amp; Photos</a>');
		document.write('<span class="arrow">&raquo;</span></td></tr>');
	}
	else{
		//document.write('<tr><td><a href="#" onclick="javascript:return noImageAvailable()" class="blu-link-02" >More Videos &amp; Photos</a>');
	}

	

}



function noImageAvailable(){
alert("Sorry! No Image Available");
return false;
}

function replaceAllInCommon( strToBeOperated, strToBeReplaced, strForReplacement ) {
			//alert("iam in ");
		for ( i = 0; i < strToBeOperated.length; i++ ) {
		var idx = strToBeOperated.indexOf(strToBeReplaced);
		while ( idx > -1 ) {
					strToBeOperated = strToBeOperated.replace(strToBeReplaced,strForReplacement ); 
					idx = strToBeOperated.indexOf(strToBeReplaced);
			}
		
		}
	return strToBeOperated;
}


function SendCategoryInfoToFinalPage(categoryInfo,categoryInfoForBreadCrumb){
	//alert("categoryInfo " + categoryInfo);
	//parent.location.href = "/alaskachannel/pages/videophoto/vp_anchorage_ss01_photo.jsp?suppliername="+categoryInfo+"&offsetForPhotoGallery=0";	
	parent.location.href = "/videos-photos/vp_anchorage_ss01.jsp?suppliername="+categoryInfo+"&offsetForPhotoGallery=0&offsetForVideoGallery=0&forBreadcrumb="+categoryInfoForBreadCrumb;
}


function validateAddVideo(addVideoActionFrom){
	return (ValidateVideoParameters(addVideoActionFrom.msVideoParameters) &&
			ValidateVideoTitles(addVideoActionFrom.msVideoTitle) &&
			ValidateVideoRelativeURI(addVideoActionFrom.msVideoRelativeURI));
	}

function ValidateVideoParameters(videoParameters){
	if ( (videoParameters.value==null)||(videoParameters.value=="") ){
		alert("Please Enter Video Parameters")
		videoParameters.focus()
		return false
	}
	return true
}
function ValidateVideoTitles(videoTitles){
	if ( (videoTitles.value==null)||(videoTitles.value=="") ){
		alert("Please Enter Video Titles")
		videoTitles.focus()
		return false
	}
	return true
}
	
function ValidateVideoRelativeURI(videoRelativeURI){
	if ( (videoRelativeURI.value==null)||(videoRelativeURI.value=="") ){
		alert("Please Enter Image Name")
		videoRelativeURI.focus()
		return false
	}
	return true
}

function videoAndPhoto(){
parent.location.href = "/videos-photos/vp_anchorage_ss01.jsp?suppliername="+breadcrumpValue+"&offsetForPhotoGallery=0&offsetForVideoGallery=0&forBreadcrumb="+breadcrumbValueForBreadcrumb;
}
